diff --git a/.changeset/swift-pets-hammer.md b/.changeset/swift-pets-hammer.md new file mode 100644 index 0000000000..0932a4e87c --- /dev/null +++ b/.changeset/swift-pets-hammer.md @@ -0,0 +1,5 @@ +--- +"@khanacademy/perseus-editor": patch +--- + +Restructure interaction-editor subcomponents diff --git a/packages/perseus-editor/src/widgets/interaction/constraint-editor.tsx b/packages/perseus-editor/src/widgets/interaction-editor/constraint-editor.tsx similarity index 100% rename from packages/perseus-editor/src/widgets/interaction/constraint-editor.tsx rename to packages/perseus-editor/src/widgets/interaction-editor/constraint-editor.tsx diff --git a/packages/perseus-editor/src/widgets/interaction-editor/function-editor.tsx b/packages/perseus-editor/src/widgets/interaction-editor/function-editor.tsx new file mode 100644 index 0000000000..fcd3594ad0 --- /dev/null +++ b/packages/perseus-editor/src/widgets/interaction-editor/function-editor.tsx @@ -0,0 +1,111 @@ +import { + components, + Changeable, + Dependencies, + EditorJsonify, + KhanColors, + ColorPicker, + DashPicker, +} from "@khanacademy/perseus"; +import PropTypes from "prop-types"; +import * as React from "react"; +import _ from "underscore"; + +const {MathInput, NumberInput} = components; +const {getDependencies} = Dependencies; + +type FunctionEditorProps = any; + +// +// Editor for function plots +// +// TODO(eater): Factor this out +// +class FunctionEditor extends React.Component { + static propTypes = { + ...Changeable.propTypes, + value: PropTypes.string, + rangeMin: PropTypes.string, + rangeMax: PropTypes.string, + color: PropTypes.string, + strokeDashArray: PropTypes.string, + strokeWidth: PropTypes.number, + }; + + static defaultProps = { + value: "x", + rangeMin: "-10", + rangeMax: "10", + color: KhanColors.BLUE, + strokeDasharray: "", + strokeWidth: 2, + }; + + change: (arg1: any, arg2?: any, arg3?: any) => any = (...args) => { + return Changeable.change.apply(this, args); + }; + + serialize = () => { + return EditorJsonify.serialize.call(this); + }; + + render(): React.ReactNode { + const {TeX} = getDependencies(); + const analyticsStub = {onAnalyticsEvent: () => Promise.resolve()}; + + return ( +
+
+ {this.props.funcName + "(x)="}{" "} + +
+
+ Range: \Large( + + ,{" "} + + \Large) +
+
+ +
+
+ +
+
+
+ Width:{" "} + +
+
+
+ ); + } +} + +export default FunctionEditor; diff --git a/packages/perseus-editor/src/widgets/interaction-editor/index.ts b/packages/perseus-editor/src/widgets/interaction-editor/index.ts new file mode 100644 index 0000000000..00c8f5909a --- /dev/null +++ b/packages/perseus-editor/src/widgets/interaction-editor/index.ts @@ -0,0 +1,3 @@ +import InteractionEditor from "./interaction-editor"; + +export default InteractionEditor; diff --git a/packages/perseus-editor/src/widgets/interaction-editor.tsx b/packages/perseus-editor/src/widgets/interaction-editor/interaction-editor.tsx similarity index 61% rename from packages/perseus-editor/src/widgets/interaction-editor.tsx rename to packages/perseus-editor/src/widgets/interaction-editor/interaction-editor.tsx index 7c0b553c1b..0fceaeb790 100644 --- a/packages/perseus-editor/src/widgets/interaction-editor.tsx +++ b/packages/perseus-editor/src/widgets/interaction-editor/interaction-editor.tsx @@ -1,26 +1,27 @@ /* eslint-disable @khanacademy/ts-no-error-suppressions */ -/* eslint-disable @babel/no-invalid-this, react/no-unsafe, react/sort-comp */ +/* eslint-disable @babel/no-invalid-this, react/no-unsafe */ import { - components, Changeable, Dependencies, EditorJsonify, - KhanColors, Util, - ArrowPicker, - ColorPicker, - DashPicker, ElementContainer, } from "@khanacademy/perseus"; import PropTypes from "prop-types"; import * as React from "react"; import _ from "underscore"; -import GraphSettings from "../components/graph-settings"; +import GraphSettings from "../../components/graph-settings"; -import ConstraintEditor from "./interaction/constraint-editor"; +import FunctionEditor from "./function-editor"; +import LabelEditor from "./label-editor"; +import LineEditor from "./line-editor"; +import MovableLineEditor from "./movable-line-editor"; +import MovablePointEditor from "./movable-point-editor"; +import ParametricEditor from "./parametric-editor"; +import PointEditor from "./point-editor"; +import RectangleEditor from "./rectangle-editor"; -const {MathInput, NumberInput, TextInput} = components; const {getDependencies} = Dependencies; const {unescapeMathMode} = Util; @@ -39,761 +40,6 @@ const defaultInteractionProps = { elements: [], } as const; -type PointEditorProps = any; - -// -// Editor for non-interactive points -// -// TODO(eater): Factor this out -// -class PointEditor extends React.Component { - static propTypes = { - ...Changeable.propTypes, - coordX: PropTypes.string, - coordY: PropTypes.string, - color: PropTypes.string, - }; - - static defaultProps = { - coordX: "0", - coordY: "0", - color: KhanColors.BLACK, - }; - - render(): React.ReactNode { - const {TeX} = getDependencies(); - const analyticsStub = {onAnalyticsEvent: () => Promise.resolve()}; - - return ( -
-
- Coordinate: \Large( - - ,{" "} - - \Large) -
-
- -
-
- ); - } - - change: (arg1: any, arg2: any, arg3: any) => any = (...args) => { - return Changeable.change.apply(this, args); - }; - - serialize = () => { - return EditorJsonify.serialize.call(this); - }; -} - -type LineEditorProps = any; - -// -// Editor for non-interactive line segments -// -// TODO(eater): Factor this out -// -class LineEditor extends React.Component { - static propTypes = { - ...Changeable.propTypes, - startX: PropTypes.string, - startY: PropTypes.string, - endX: PropTypes.string, - endY: PropTypes.string, - color: PropTypes.string, - strokeDasharray: PropTypes.string, - arrows: PropTypes.string, - strokeWidth: PropTypes.number, - }; - - static defaultProps = { - startX: "-5", - startY: "5", - endX: "5", - endY: "5", - color: KhanColors.BLACK, - strokeDasharray: "", - arrows: "", - strokeWidth: 2, - }; - - render(): React.ReactNode { - const {TeX} = getDependencies(); - const analyticsStub = {onAnalyticsEvent: () => Promise.resolve()}; - - return ( -
-
- Start: \Large( - - ,{" "} - - \Large) -
-
- End: \Large( - - ,{" "} - - \Large) -
-
- -
-
- -     - -
-
-
- Width:{" "} - -
-
-
- ); - } - - change: (arg1: any, arg2: any, arg3: any) => any = (...args) => { - return Changeable.change.apply(this, args); - }; - - serialize = () => { - return EditorJsonify.serialize.call(this); - }; -} - -type MovablePointEditorProps = any; - -// -// Editor for interactive movable points -// -// TODO(eater): Factor this out -// TODO(eater): Rethink how constraints are represented -// -class MovablePointEditor extends React.Component { - static propTypes = { - ...Changeable.propTypes, - startX: PropTypes.string, - startY: PropTypes.string, - constraint: PropTypes.string, - snap: PropTypes.number, - constraintFn: PropTypes.string, - }; - - static defaultProps = { - startX: "0", - startY: "0", - constraint: "none", - snap: 0.5, - constraintFn: "0", - constraintXMin: "-10", - constraintXMax: "10", - constraintYMin: "-10", - constraintYMax: "10", - }; - - render(): React.ReactNode { - const {TeX} = getDependencies(); - const analyticsStub = {onAnalyticsEvent: () => Promise.resolve()}; - - return ( -
-
- Start: \Large( - - ,{" "} - - \Large) -
-
- Update (x_n, y_n) for n ={" "} - -
- {/* @ts-expect-error - TS2769 - No overload matches this call. */} - -
- ); - } - - change = (...args) => { - return Changeable.change.apply(this, args); - }; - - serialize = () => { - return EditorJsonify.serialize.call(this); - }; -} - -type MovableLineEditorProps = any; - -// -// Editor for interactive movable line segments -// -// TODO(eater): Factor this out -// TODO(eater): Rethink how constraints are represented -// -class MovableLineEditor extends React.Component { - static propTypes = { - ...Changeable.propTypes, - startX: PropTypes.string, - startY: PropTypes.string, - endX: PropTypes.string, - endY: PropTypes.string, - constraint: PropTypes.string, - snap: PropTypes.number, - constraintFn: PropTypes.string, - }; - - static defaultProps = { - startX: "-5", - startY: "5", - endX: "5", - endY: "5", - constraint: "none", - snap: 0.5, - constraintFn: "0", - constraintXMin: "-10", - constraintXMax: "10", - constraintYMin: "-10", - constraintYMax: "10", - }; - - render(): React.ReactNode { - const {TeX} = getDependencies(); - const analyticsStub = {onAnalyticsEvent: () => Promise.resolve()}; - - return ( -
- Initial position: -
- Start: \Large( - - ,{" "} - - \Large) -
-
- End: \Large( - - ,{" "} - - \Large) -
-
- Start updates (x_n, y_n) for n = - -
-
- End updates (x_m, y_m) for m = - -
-
- All constraints are applied to the start point. -
- {/* @ts-expect-error - TS2769 - No overload matches this call. */} - -
- ); - } - - change = (...args) => { - return Changeable.change.apply(this, args); - }; - - serialize = () => { - return EditorJsonify.serialize.call(this); - }; -} - -type FunctionEditorProps = any; - -// -// Editor for function plots -// -// TODO(eater): Factor this out -// -class FunctionEditor extends React.Component { - static propTypes = { - ...Changeable.propTypes, - value: PropTypes.string, - rangeMin: PropTypes.string, - rangeMax: PropTypes.string, - color: PropTypes.string, - strokeDashArray: PropTypes.string, - strokeWidth: PropTypes.number, - }; - - static defaultProps = { - value: "x", - rangeMin: "-10", - rangeMax: "10", - color: KhanColors.BLUE, - strokeDasharray: "", - strokeWidth: 2, - }; - - render(): React.ReactNode { - const {TeX} = getDependencies(); - const analyticsStub = {onAnalyticsEvent: () => Promise.resolve()}; - - return ( -
-
- {this.props.funcName + "(x)="}{" "} - -
-
- Range: \Large( - - ,{" "} - - \Large) -
-
- -
-
- -
-
-
- Width:{" "} - -
-
-
- ); - } - - change: (arg1: any, arg2: any, arg3: any) => any = (...args) => { - return Changeable.change.apply(this, args); - }; - - serialize = () => { - return EditorJsonify.serialize.call(this); - }; -} - -type ParametricEditorProps = any; - -// -// Editor for parametric plots -// -// TODO(eater): Factor this out -// -class ParametricEditor extends React.Component { - static propTypes = { - ...Changeable.propTypes, - x: PropTypes.string, - y: PropTypes.string, - rangeMin: PropTypes.string, - rangeMax: PropTypes.string, - color: PropTypes.string, - strokeDashArray: PropTypes.string, - strokeWidth: PropTypes.number, - }; - - static defaultProps = { - x: "cos(t)", - y: "sin(t)", - rangeMin: "0", - rangeMax: "2\\pi", - color: KhanColors.BLUE, - strokeDasharray: "", - strokeWidth: 2, - }; - - render(): React.ReactNode { - const {TeX} = getDependencies(); - const analyticsStub = {onAnalyticsEvent: () => Promise.resolve()}; - - return ( -
-
- X(t) ={" "} - -
-
- Y(t) ={" "} - -
-
- Range: \Large( - - ,{" "} - - \Large) -
-
- -
-
- -
-
-
- Width:{" "} - -
-
-
- ); - } - - change: (arg1: any, arg2: any, arg3: any) => any = (...args) => { - return Changeable.change.apply(this, args); - }; - - serialize = () => { - return EditorJsonify.serialize.call(this); - }; -} - -type LabelEditorProps = any; - -// -// Editor for labels -// -// TODO(eater): Factor this out maybe? -// TODO(eater): Add text direction -// -class LabelEditor extends React.Component { - static propTypes = { - ...Changeable.propTypes, - color: PropTypes.string, - coordX: PropTypes.string, - coordY: PropTypes.string, - label: PropTypes.string, - }; - - static defaultProps = { - coordX: "0", - coordY: "0", - color: KhanColors.BLACK, - label: "\\phi", - }; - - render(): React.ReactNode { - const {TeX} = getDependencies(); - const analyticsStub = {onAnalyticsEvent: () => Promise.resolve()}; - - return ( -
-
- -
-
- Location: \Large( - - ,{" "} - - \Large) -
-
- -
-
- ); - } - - change: (arg1: any, arg2: any, arg3: any) => any = (...args) => { - return Changeable.change.apply(this, args); - }; - - serialize = () => { - return EditorJsonify.serialize.call(this); - }; -} - -type RectangleEditorProps = any; - -// -// Editor for rectangles -// -// TODO(eater): Factor this out maybe? -// -class RectangleEditor extends React.Component { - static propTypes = { - ...Changeable.propTypes, - color: PropTypes.string, - coordX: PropTypes.string, - coordY: PropTypes.string, - height: PropTypes.string, - width: PropTypes.string, - }; - - static defaultProps = { - coordX: "-5", - coordY: "5", - width: "2", - height: "3", - color: KhanColors.LIGHT_BLUE, - }; - - render(): React.ReactNode { - const {TeX} = getDependencies(); - const analyticsStub = {onAnalyticsEvent: () => Promise.resolve()}; - - return ( -
-
- Bottom left: \Large( - - ,{" "} - - \Large) -
-
- Width:{" "} - -
-
- Height:{" "} - -
-
- -
-
- You want a border? Sorry, draw your own. -
-
- ); - } - - change: (arg1: any, arg2: any, arg3: any) => any = (...args) => { - return Changeable.change.apply(this, args); - }; - - serialize = () => { - return EditorJsonify.serialize.call(this); - }; -} - type InteractionEditorProps = any; type InteractionEditorState = any; @@ -956,6 +202,10 @@ class InteractionEditor extends React.Component< return Changeable.change.apply(this, args); }; + serialize: () => any = () => { + return EditorJsonify.serialize.call(this); + }; + render(): React.ReactNode { const {TeX} = getDependencies(); @@ -1487,10 +737,6 @@ class InteractionEditor extends React.Component< ); /* eslint-enable max-len */ } - - serialize: () => any = () => { - return EditorJsonify.serialize.call(this); - }; } export default InteractionEditor; diff --git a/packages/perseus-editor/src/widgets/interaction-editor/label-editor.tsx b/packages/perseus-editor/src/widgets/interaction-editor/label-editor.tsx new file mode 100644 index 0000000000..c2d457d96b --- /dev/null +++ b/packages/perseus-editor/src/widgets/interaction-editor/label-editor.tsx @@ -0,0 +1,91 @@ +import { + components, + Changeable, + Dependencies, + EditorJsonify, + KhanColors, + ColorPicker, +} from "@khanacademy/perseus"; +import PropTypes from "prop-types"; +import * as React from "react"; +import _ from "underscore"; + +const {MathInput, TextInput} = components; +const {getDependencies} = Dependencies; + +type LabelEditorProps = any; + +// +// Editor for labels +// +// TODO(eater): Factor this out maybe? +// TODO(eater): Add text direction +// +class LabelEditor extends React.Component { + static propTypes = { + ...Changeable.propTypes, + color: PropTypes.string, + coordX: PropTypes.string, + coordY: PropTypes.string, + label: PropTypes.string, + }; + + static defaultProps = { + coordX: "0", + coordY: "0", + color: KhanColors.BLACK, + label: "\\phi", + }; + + change: (arg1: any, arg2?: any, arg3?: any) => any = (...args) => { + return Changeable.change.apply(this, args); + }; + + serialize = () => { + return EditorJsonify.serialize.call(this); + }; + + render(): React.ReactNode { + const {TeX} = getDependencies(); + const analyticsStub = {onAnalyticsEvent: () => Promise.resolve()}; + + return ( +
+
+ +
+
+ Location: \Large( + + ,{" "} + + \Large) +
+
+ +
+
+ ); + } +} + +export default LabelEditor; diff --git a/packages/perseus-editor/src/widgets/interaction-editor/line-editor.tsx b/packages/perseus-editor/src/widgets/interaction-editor/line-editor.tsx new file mode 100644 index 0000000000..5a78e50339 --- /dev/null +++ b/packages/perseus-editor/src/widgets/interaction-editor/line-editor.tsx @@ -0,0 +1,129 @@ +import { + components, + Changeable, + Dependencies, + EditorJsonify, + KhanColors, + ArrowPicker, + ColorPicker, + DashPicker, +} from "@khanacademy/perseus"; +import PropTypes from "prop-types"; +import * as React from "react"; +import _ from "underscore"; + +const {MathInput, NumberInput} = components; +const {getDependencies} = Dependencies; + +type LineEditorProps = any; + +// +// Editor for non-interactive line segments +// +// TODO(eater): Factor this out +// +class LineEditor extends React.Component { + static propTypes = { + ...Changeable.propTypes, + startX: PropTypes.string, + startY: PropTypes.string, + endX: PropTypes.string, + endY: PropTypes.string, + color: PropTypes.string, + strokeDasharray: PropTypes.string, + arrows: PropTypes.string, + strokeWidth: PropTypes.number, + }; + + static defaultProps = { + startX: "-5", + startY: "5", + endX: "5", + endY: "5", + color: KhanColors.BLACK, + strokeDasharray: "", + arrows: "", + strokeWidth: 2, + }; + + change: (arg1: any, arg2?: any, arg3?: any) => any = (...args) => { + return Changeable.change.apply(this, args); + }; + + serialize = () => { + return EditorJsonify.serialize.call(this); + }; + + render(): React.ReactNode { + const {TeX} = getDependencies(); + const analyticsStub = {onAnalyticsEvent: () => Promise.resolve()}; + + return ( +
+
+ Start: \Large( + + ,{" "} + + \Large) +
+
+ End: \Large( + + ,{" "} + + \Large) +
+
+ +
+
+ +     + +
+
+
+ Width:{" "} + +
+
+
+ ); + } +} + +export default LineEditor; diff --git a/packages/perseus-editor/src/widgets/interaction-editor/movable-line-editor.tsx b/packages/perseus-editor/src/widgets/interaction-editor/movable-line-editor.tsx new file mode 100644 index 0000000000..dbe1fa0985 --- /dev/null +++ b/packages/perseus-editor/src/widgets/interaction-editor/movable-line-editor.tsx @@ -0,0 +1,125 @@ +import { + components, + Changeable, + Dependencies, + EditorJsonify, +} from "@khanacademy/perseus"; +import PropTypes from "prop-types"; +import * as React from "react"; +import _ from "underscore"; + +import ConstraintEditor from "./constraint-editor"; + +const {MathInput, NumberInput} = components; +const {getDependencies} = Dependencies; + +type MovableLineEditorProps = any; + +// +// Editor for interactive movable line segments +// +// TODO(eater): Factor this out +// TODO(eater): Rethink how constraints are represented +// +class MovableLineEditor extends React.Component { + static propTypes = { + ...Changeable.propTypes, + startX: PropTypes.string, + startY: PropTypes.string, + endX: PropTypes.string, + endY: PropTypes.string, + constraint: PropTypes.string, + snap: PropTypes.number, + constraintFn: PropTypes.string, + }; + + static defaultProps = { + startX: "-5", + startY: "5", + endX: "5", + endY: "5", + constraint: "none", + snap: 0.5, + constraintFn: "0", + constraintXMin: "-10", + constraintXMax: "10", + constraintYMin: "-10", + constraintYMax: "10", + }; + + change = (...args) => { + return Changeable.change.apply(this, args); + }; + + serialize = () => { + return EditorJsonify.serialize.call(this); + }; + + render(): React.ReactNode { + const {TeX} = getDependencies(); + const analyticsStub = {onAnalyticsEvent: () => Promise.resolve()}; + + return ( +
+ Initial position: +
+ Start: \Large( + + ,{" "} + + \Large) +
+
+ End: \Large( + + ,{" "} + + \Large) +
+
+ Start updates (x_n, y_n) for n = + +
+
+ End updates (x_m, y_m) for m = + +
+
+ All constraints are applied to the start point. +
+ {/* @ts-expect-error - TS2769 - No overload matches this call. */} + +
+ ); + } +} + +export default MovableLineEditor; diff --git a/packages/perseus-editor/src/widgets/interaction-editor/movable-point-editor.tsx b/packages/perseus-editor/src/widgets/interaction-editor/movable-point-editor.tsx new file mode 100644 index 0000000000..8f8b71e9cc --- /dev/null +++ b/packages/perseus-editor/src/widgets/interaction-editor/movable-point-editor.tsx @@ -0,0 +1,92 @@ +import { + components, + Changeable, + Dependencies, + EditorJsonify, +} from "@khanacademy/perseus"; +import PropTypes from "prop-types"; +import * as React from "react"; +import _ from "underscore"; + +import ConstraintEditor from "./constraint-editor"; + +const {MathInput, NumberInput} = components; +const {getDependencies} = Dependencies; + +type MovablePointEditorProps = any; + +// +// Editor for interactive movable points +// +// TODO(eater): Factor this out +// TODO(eater): Rethink how constraints are represented +// +class MovablePointEditor extends React.Component { + static propTypes = { + ...Changeable.propTypes, + startX: PropTypes.string, + startY: PropTypes.string, + constraint: PropTypes.string, + snap: PropTypes.number, + constraintFn: PropTypes.string, + }; + + static defaultProps = { + startX: "0", + startY: "0", + constraint: "none", + snap: 0.5, + constraintFn: "0", + constraintXMin: "-10", + constraintXMax: "10", + constraintYMin: "-10", + constraintYMax: "10", + }; + + change = (...args) => { + return Changeable.change.apply(this, args); + }; + + serialize = () => { + return EditorJsonify.serialize.call(this); + }; + + render(): React.ReactNode { + const {TeX} = getDependencies(); + const analyticsStub = {onAnalyticsEvent: () => Promise.resolve()}; + + return ( +
+
+ Start: \Large( + + ,{" "} + + \Large) +
+
+ Update (x_n, y_n) for n ={" "} + +
+ {/* @ts-expect-error - TS2769 - No overload matches this call. */} + +
+ ); + } +} + +export default MovablePointEditor; diff --git a/packages/perseus-editor/src/widgets/interaction-editor/parametric-editor.tsx b/packages/perseus-editor/src/widgets/interaction-editor/parametric-editor.tsx new file mode 100644 index 0000000000..dea79f31f5 --- /dev/null +++ b/packages/perseus-editor/src/widgets/interaction-editor/parametric-editor.tsx @@ -0,0 +1,122 @@ +import { + components, + Changeable, + Dependencies, + EditorJsonify, + KhanColors, + ColorPicker, + DashPicker, +} from "@khanacademy/perseus"; +import PropTypes from "prop-types"; +import * as React from "react"; +import _ from "underscore"; + +const {MathInput, NumberInput} = components; +const {getDependencies} = Dependencies; + +type ParametricEditorProps = any; + +// +// Editor for parametric plots +// +// TODO(eater): Factor this out +// +class ParametricEditor extends React.Component { + static propTypes = { + ...Changeable.propTypes, + x: PropTypes.string, + y: PropTypes.string, + rangeMin: PropTypes.string, + rangeMax: PropTypes.string, + color: PropTypes.string, + strokeDashArray: PropTypes.string, + strokeWidth: PropTypes.number, + }; + + static defaultProps = { + x: "cos(t)", + y: "sin(t)", + rangeMin: "0", + rangeMax: "2\\pi", + color: KhanColors.BLUE, + strokeDasharray: "", + strokeWidth: 2, + }; + + change: (arg1: any, arg2?: any, arg3?: any) => any = (...args) => { + return Changeable.change.apply(this, args); + }; + + serialize = () => { + return EditorJsonify.serialize.call(this); + }; + + render(): React.ReactNode { + const {TeX} = getDependencies(); + const analyticsStub = {onAnalyticsEvent: () => Promise.resolve()}; + + return ( +
+
+ X(t) ={" "} + +
+
+ Y(t) ={" "} + +
+
+ Range: \Large( + + ,{" "} + + \Large) +
+
+ +
+
+ +
+
+
+ Width:{" "} + +
+
+
+ ); + } +} + +export default ParametricEditor; diff --git a/packages/perseus-editor/src/widgets/interaction-editor/point-editor.tsx b/packages/perseus-editor/src/widgets/interaction-editor/point-editor.tsx new file mode 100644 index 0000000000..3e49d15e4f --- /dev/null +++ b/packages/perseus-editor/src/widgets/interaction-editor/point-editor.tsx @@ -0,0 +1,79 @@ +import { + components, + Changeable, + Dependencies, + EditorJsonify, + KhanColors, + ColorPicker, +} from "@khanacademy/perseus"; +import PropTypes from "prop-types"; +import * as React from "react"; +import _ from "underscore"; + +const {MathInput} = components; +const {getDependencies} = Dependencies; + +type PointEditorProps = any; + +// +// Editor for non-interactive points +// +// TODO(eater): Factor this out +// +class PointEditor extends React.Component { + static propTypes = { + ...Changeable.propTypes, + coordX: PropTypes.string, + coordY: PropTypes.string, + color: PropTypes.string, + }; + + static defaultProps = { + coordX: "0", + coordY: "0", + color: KhanColors.BLACK, + }; + + change: (arg1: any, arg2?: any, arg3?: any) => any = (...args) => { + return Changeable.change.apply(this, args); + }; + + serialize = () => { + return EditorJsonify.serialize.call(this); + }; + + render(): React.ReactNode { + const {TeX} = getDependencies(); + const analyticsStub = {onAnalyticsEvent: () => Promise.resolve()}; + + return ( +
+
+ Coordinate: \Large( + + ,{" "} + + \Large) +
+
+ +
+
+ ); + } +} + +export default PointEditor; diff --git a/packages/perseus-editor/src/widgets/interaction-editor/rectangle-editor.tsx b/packages/perseus-editor/src/widgets/interaction-editor/rectangle-editor.tsx new file mode 100644 index 0000000000..ba876dbeec --- /dev/null +++ b/packages/perseus-editor/src/widgets/interaction-editor/rectangle-editor.tsx @@ -0,0 +1,105 @@ +import { + components, + Changeable, + Dependencies, + EditorJsonify, + KhanColors, + ColorPicker, +} from "@khanacademy/perseus"; +import PropTypes from "prop-types"; +import * as React from "react"; +import _ from "underscore"; + +const {MathInput} = components; +const {getDependencies} = Dependencies; + +type RectangleEditorProps = any; + +// +// Editor for rectangles +// +// TODO(eater): Factor this out maybe? +// +class RectangleEditor extends React.Component { + static propTypes = { + ...Changeable.propTypes, + color: PropTypes.string, + coordX: PropTypes.string, + coordY: PropTypes.string, + height: PropTypes.string, + width: PropTypes.string, + }; + + static defaultProps = { + coordX: "-5", + coordY: "5", + width: "2", + height: "3", + color: KhanColors.LIGHT_BLUE, + }; + + change: (arg1: any, arg2?: any, arg3?: any) => any = (...args) => { + return Changeable.change.apply(this, args); + }; + + serialize = () => { + return EditorJsonify.serialize.call(this); + }; + + render(): React.ReactNode { + const {TeX} = getDependencies(); + const analyticsStub = {onAnalyticsEvent: () => Promise.resolve()}; + + return ( +
+
+ Bottom left: \Large( + + ,{" "} + + \Large) +
+
+ Width:{" "} + +
+
+ Height:{" "} + +
+
+ +
+
+ You want a border? Sorry, draw your own. +
+
+ ); + } +} + +export default RectangleEditor;