@khanacademy/perseus-editor 5.0.1 → 5.0.2
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.
|
@@ -1,34 +1,83 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import type { PerseusImageBackground } from "@khanacademy/perseus";
|
|
3
|
-
type
|
|
3
|
+
type Range = [min: number, max: number];
|
|
4
4
|
type Props = {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* The size of the graph area in pixels.
|
|
7
|
+
*/
|
|
8
|
+
box: [x: number, y: number];
|
|
9
|
+
/**
|
|
10
|
+
* The labels for the x and y axes.
|
|
11
|
+
*/
|
|
7
12
|
labels: ReadonlyArray<string>;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
13
|
+
/**
|
|
14
|
+
* The range of the graph.
|
|
15
|
+
*/
|
|
16
|
+
range: [x: Range, y: Range];
|
|
17
|
+
/**
|
|
18
|
+
* How far apart the tick marks on the axes are in the x and y
|
|
19
|
+
* directions.
|
|
20
|
+
*/
|
|
21
|
+
step: [x: number, y: number];
|
|
22
|
+
/**
|
|
23
|
+
* How far apart the grid lines are in the x and y directions.
|
|
24
|
+
*/
|
|
25
|
+
gridStep: [x: number, y: number];
|
|
26
|
+
/**
|
|
27
|
+
* How far apart the snap-to points are in the x and y directions.
|
|
28
|
+
*/
|
|
29
|
+
snapStep: [x: number, y: number];
|
|
30
|
+
/**
|
|
31
|
+
* An error message to display in the graph area, or true if the
|
|
32
|
+
* graph is valid.
|
|
33
|
+
*/
|
|
12
34
|
valid: boolean | string;
|
|
35
|
+
/**
|
|
36
|
+
* The background image to display in the graph area and its properties.
|
|
37
|
+
*/
|
|
13
38
|
backgroundImage: PerseusImageBackground;
|
|
39
|
+
/**
|
|
40
|
+
* The type of markings to display on the graph.
|
|
41
|
+
* - graph: shows the axes and the grid lines
|
|
42
|
+
* - grid: shows only the grid lines
|
|
43
|
+
* - none: shows no markings
|
|
44
|
+
*/
|
|
14
45
|
markings: "graph" | "grid" | "none";
|
|
46
|
+
/**
|
|
47
|
+
* Whether to show the protractor on the graph.
|
|
48
|
+
*/
|
|
15
49
|
showProtractor: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Whether to show the ruler on the graph.
|
|
52
|
+
*/
|
|
16
53
|
showRuler: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Whether to show tooltips on the graph.
|
|
56
|
+
*/
|
|
17
57
|
showTooltips: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* The label to display on the ruler, if any.
|
|
60
|
+
*/
|
|
18
61
|
rulerLabel: string;
|
|
62
|
+
/**
|
|
63
|
+
* The number of ticks to display on the ruler.
|
|
64
|
+
*/
|
|
19
65
|
rulerTicks: number;
|
|
20
66
|
onChange: (arg1: Partial<Props>) => void;
|
|
21
67
|
};
|
|
22
68
|
type State = {
|
|
23
69
|
labelsTextbox: ReadonlyArray<string>;
|
|
24
|
-
gridStepTextbox: [number, number];
|
|
25
|
-
snapStepTextbox: [number, number];
|
|
26
|
-
stepTextbox: [number, number];
|
|
27
|
-
rangeTextbox: [
|
|
70
|
+
gridStepTextbox: [x: number, y: number];
|
|
71
|
+
snapStepTextbox: [x: number, y: number];
|
|
72
|
+
stepTextbox: [x: number, y: number];
|
|
73
|
+
rangeTextbox: [x: Range, y: Range];
|
|
28
74
|
backgroundImage: PerseusImageBackground;
|
|
29
75
|
};
|
|
30
76
|
declare class InteractiveGraphSettings extends React.Component<Props, State> {
|
|
31
77
|
_isMounted: boolean;
|
|
78
|
+
bgUrlRef: React.RefObject<HTMLInputElement>;
|
|
79
|
+
labelXRef: React.RefObject<HTMLInputElement>;
|
|
80
|
+
labelYRef: React.RefObject<HTMLInputElement>;
|
|
32
81
|
static stateFromProps(props: any): {
|
|
33
82
|
labelsTextbox: any;
|
|
34
83
|
gridStepTextbox: any;
|
|
@@ -39,7 +88,6 @@ declare class InteractiveGraphSettings extends React.Component<Props, State> {
|
|
|
39
88
|
};
|
|
40
89
|
constructor(props: Props);
|
|
41
90
|
static defaultProps: {
|
|
42
|
-
editableSettings: string[];
|
|
43
91
|
box: 288[];
|
|
44
92
|
labels: string[];
|
|
45
93
|
range: number[][];
|
|
@@ -66,7 +114,7 @@ declare class InteractiveGraphSettings extends React.Component<Props, State> {
|
|
|
66
114
|
changeRulerLabel: (e: any) => void;
|
|
67
115
|
changeRulerTicks: (e: any) => void;
|
|
68
116
|
changeBackgroundUrl: (e: any) => void;
|
|
69
|
-
renderLabelChoices: (choices: any) =>
|
|
117
|
+
renderLabelChoices: (choices: any) => any;
|
|
70
118
|
validRange: (range: any) => true | "Range must be a valid number" | "Range must have a higher number on the right";
|
|
71
119
|
validateStepValue: (settings: any) => string | true;
|
|
72
120
|
validSnapStep: (step: any, range: any) => string | true;
|
package/dist/es/index.js
CHANGED
|
@@ -25,7 +25,7 @@ import * as i18n$1 from '@khanacademy/wonder-blocks-i18n';
|
|
|
25
25
|
|
|
26
26
|
// This file is processed by a Rollup plugin (replace) to inject the production
|
|
27
27
|
const libName = "@khanacademy/perseus-editor";
|
|
28
|
-
const libVersion = "5.0.
|
|
28
|
+
const libVersion = "5.0.2";
|
|
29
29
|
addLibraryVersionToPerseusDebug(libName, libVersion);
|
|
30
30
|
|
|
31
31
|
function _extends() {
|
|
@@ -27488,7 +27488,6 @@ const GraphSettings = createReactClass({
|
|
|
27488
27488
|
const {
|
|
27489
27489
|
TeX
|
|
27490
27490
|
} = Dependencies.getDependencies();
|
|
27491
|
-
this.props.box; // ?
|
|
27492
27491
|
return /*#__PURE__*/React.createElement("div", null, _.contains(this.props.editableSettings, "canvas") && /*#__PURE__*/React.createElement("div", {
|
|
27493
27492
|
className: "graph-settings"
|
|
27494
27493
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -29525,7 +29524,6 @@ const GraphTypeSelector = props => {
|
|
|
29525
29524
|
}, "Angle"));
|
|
29526
29525
|
};
|
|
29527
29526
|
|
|
29528
|
-
/* eslint-disable react/forbid-prop-types, react/no-unsafe */
|
|
29529
29527
|
const {
|
|
29530
29528
|
ButtonGroup: ButtonGroup$2,
|
|
29531
29529
|
InfoTip: InfoTip$c,
|
|
@@ -29548,12 +29546,16 @@ class InteractiveGraphSettings extends React.Component {
|
|
|
29548
29546
|
snapStepTextbox: props.snapStep,
|
|
29549
29547
|
stepTextbox: props.step,
|
|
29550
29548
|
rangeTextbox: props.range,
|
|
29551
|
-
|
|
29549
|
+
// Shallow-copied clone
|
|
29550
|
+
backgroundImage: _extends({}, props.backgroundImage)
|
|
29552
29551
|
};
|
|
29553
29552
|
}
|
|
29554
29553
|
constructor(props) {
|
|
29555
29554
|
super(props);
|
|
29556
29555
|
this._isMounted = false;
|
|
29556
|
+
this.bgUrlRef = /*#__PURE__*/React.createRef();
|
|
29557
|
+
this.labelXRef = /*#__PURE__*/React.createRef();
|
|
29558
|
+
this.labelYRef = /*#__PURE__*/React.createRef();
|
|
29557
29559
|
this.change = (...args) => {
|
|
29558
29560
|
return Changeable.change.apply(this, args);
|
|
29559
29561
|
};
|
|
@@ -29570,12 +29572,14 @@ class InteractiveGraphSettings extends React.Component {
|
|
|
29570
29572
|
});
|
|
29571
29573
|
};
|
|
29572
29574
|
this.changeBackgroundUrl = e => {
|
|
29575
|
+
var _this$bgUrlRef$curren;
|
|
29573
29576
|
// Only continue on blur or "enter"
|
|
29574
29577
|
if (e.type === "keypress" && e.key !== "Enter") {
|
|
29575
29578
|
return;
|
|
29576
29579
|
}
|
|
29577
29580
|
const setUrl = (url, width, height) => {
|
|
29578
|
-
|
|
29581
|
+
// Shallow-copied clone
|
|
29582
|
+
const image = _extends({}, this.props.backgroundImage);
|
|
29579
29583
|
image.url = url;
|
|
29580
29584
|
image.width = width;
|
|
29581
29585
|
image.height = height;
|
|
@@ -29583,9 +29587,7 @@ class InteractiveGraphSettings extends React.Component {
|
|
|
29583
29587
|
backgroundImage: image
|
|
29584
29588
|
}, this.changeGraph);
|
|
29585
29589
|
};
|
|
29586
|
-
|
|
29587
|
-
// @ts-expect-error - TS2531 - Object is possibly 'null'. | TS2339 - Property 'value' does not exist on type 'Element | Text'.
|
|
29588
|
-
const url = ReactDOM.findDOMNode(this.refs["bg-url"]).value; // eslint-disable-line react/no-string-refs
|
|
29590
|
+
const url = (_this$bgUrlRef$curren = this.bgUrlRef.current) == null ? void 0 : _this$bgUrlRef$curren.value;
|
|
29589
29591
|
if (url) {
|
|
29590
29592
|
Util.getImageSize(url, (width, height) => {
|
|
29591
29593
|
if (this._isMounted) {
|
|
@@ -29597,11 +29599,10 @@ class InteractiveGraphSettings extends React.Component {
|
|
|
29597
29599
|
}
|
|
29598
29600
|
};
|
|
29599
29601
|
this.renderLabelChoices = choices => {
|
|
29600
|
-
return
|
|
29601
|
-
|
|
29602
|
-
|
|
29603
|
-
|
|
29604
|
-
});
|
|
29602
|
+
return choices.map(nameAndValue => /*#__PURE__*/React.createElement("option", {
|
|
29603
|
+
key: nameAndValue[1],
|
|
29604
|
+
value: nameAndValue[1]
|
|
29605
|
+
}, nameAndValue[0]));
|
|
29605
29606
|
};
|
|
29606
29607
|
this.validRange = range => {
|
|
29607
29608
|
const numbers = _.every(range, function (num) {
|
|
@@ -29623,9 +29624,6 @@ class InteractiveGraphSettings extends React.Component {
|
|
|
29623
29624
|
minTicks,
|
|
29624
29625
|
maxTicks
|
|
29625
29626
|
} = settings;
|
|
29626
|
-
if (!_.isFinite(step)) {
|
|
29627
|
-
return name + " must be a valid number";
|
|
29628
|
-
}
|
|
29629
29627
|
const nSteps = numSteps(range, step);
|
|
29630
29628
|
if (nSteps < minTicks) {
|
|
29631
29629
|
return name + " is too large, there must be at least " + minTicks + " ticks.";
|
|
@@ -29811,27 +29809,7 @@ class InteractiveGraphSettings extends React.Component {
|
|
|
29811
29809
|
this._isMounted = false;
|
|
29812
29810
|
}
|
|
29813
29811
|
render() {
|
|
29814
|
-
|
|
29815
|
-
const {
|
|
29816
|
-
TeX
|
|
29817
|
-
} = Dependencies.getDependencies();
|
|
29818
|
-
return /*#__PURE__*/React.createElement("div", null, _.contains(this.props.editableSettings, "canvas") && /*#__PURE__*/React.createElement("div", {
|
|
29819
|
-
className: "graph-settings"
|
|
29820
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
29821
|
-
className: "perseus-widget-row"
|
|
29822
|
-
}, /*#__PURE__*/React.createElement("label", {
|
|
29823
|
-
htmlFor: "canvas-size"
|
|
29824
|
-
}, "Canvas size (x,y pixels)"), /*#__PURE__*/React.createElement(RangeInput$4, {
|
|
29825
|
-
id: "canvas-size",
|
|
29826
|
-
value: this.props.box,
|
|
29827
|
-
onChange: box => {
|
|
29828
|
-
this.change({
|
|
29829
|
-
box: box
|
|
29830
|
-
});
|
|
29831
|
-
}
|
|
29832
|
-
})), /*#__PURE__*/React.createElement("div", {
|
|
29833
|
-
className: "perseus-widget-row"
|
|
29834
|
-
}, "Scale (px per div):", " ", /*#__PURE__*/React.createElement(TeX, null, "(" + scale[0] + ", " + scale[1] + ")"))), _.contains(this.props.editableSettings, "graph") && /*#__PURE__*/React.createElement("div", {
|
|
29812
|
+
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
|
|
29835
29813
|
className: "graph-settings"
|
|
29836
29814
|
}, /*#__PURE__*/React.createElement("div", {
|
|
29837
29815
|
className: "perseus-widget-row"
|
|
@@ -29842,10 +29820,8 @@ class InteractiveGraphSettings extends React.Component {
|
|
|
29842
29820
|
}, "x Label"), /*#__PURE__*/React.createElement("input", {
|
|
29843
29821
|
id: "labels-x",
|
|
29844
29822
|
type: "text",
|
|
29845
|
-
className: "graph-settings-axis-label"
|
|
29846
|
-
|
|
29847
|
-
,
|
|
29848
|
-
ref: "labels-0",
|
|
29823
|
+
className: "graph-settings-axis-label",
|
|
29824
|
+
ref: this.labelXRef,
|
|
29849
29825
|
onChange: e => this.changeLabel(0, e),
|
|
29850
29826
|
value: this.state.labelsTextbox[0] || ""
|
|
29851
29827
|
})), /*#__PURE__*/React.createElement("div", {
|
|
@@ -29855,10 +29831,8 @@ class InteractiveGraphSettings extends React.Component {
|
|
|
29855
29831
|
}, "y Label"), /*#__PURE__*/React.createElement("input", {
|
|
29856
29832
|
id: "labels-y",
|
|
29857
29833
|
type: "text",
|
|
29858
|
-
className: "graph-settings-axis-label"
|
|
29859
|
-
|
|
29860
|
-
,
|
|
29861
|
-
ref: "labels-1",
|
|
29834
|
+
className: "graph-settings-axis-label",
|
|
29835
|
+
ref: this.labelYRef,
|
|
29862
29836
|
onChange: e => this.changeLabel(1, e),
|
|
29863
29837
|
value: this.state.labelsTextbox[1] || ""
|
|
29864
29838
|
}))), /*#__PURE__*/React.createElement("div", {
|
|
@@ -29897,7 +29871,7 @@ class InteractiveGraphSettings extends React.Component {
|
|
|
29897
29871
|
id: "grid-step",
|
|
29898
29872
|
value: this.state.gridStepTextbox,
|
|
29899
29873
|
onChange: this.changeGridStep
|
|
29900
|
-
}))),
|
|
29874
|
+
}))), /*#__PURE__*/React.createElement("div", {
|
|
29901
29875
|
className: "perseus-widget-row"
|
|
29902
29876
|
}, /*#__PURE__*/React.createElement("div", {
|
|
29903
29877
|
className: "perseus-widget-left-col"
|
|
@@ -29929,17 +29903,15 @@ class InteractiveGraphSettings extends React.Component {
|
|
|
29929
29903
|
label: "Show tooltips",
|
|
29930
29904
|
showTooltips: this.props.showTooltips,
|
|
29931
29905
|
onChange: this.change
|
|
29932
|
-
}))),
|
|
29906
|
+
}))), /*#__PURE__*/React.createElement("div", {
|
|
29933
29907
|
className: "image-settings"
|
|
29934
29908
|
}, /*#__PURE__*/React.createElement("div", null, "Background image:"), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("label", {
|
|
29935
29909
|
htmlFor: "bg-url"
|
|
29936
29910
|
}, "Url:"), /*#__PURE__*/React.createElement("input", {
|
|
29937
29911
|
id: "bg-url",
|
|
29938
29912
|
type: "text",
|
|
29939
|
-
className: "graph-settings-background-url"
|
|
29940
|
-
|
|
29941
|
-
,
|
|
29942
|
-
ref: "bg-url",
|
|
29913
|
+
className: "graph-settings-background-url",
|
|
29914
|
+
ref: this.bgUrlRef,
|
|
29943
29915
|
value: this.state.backgroundImage.url || "",
|
|
29944
29916
|
onChange: e => {
|
|
29945
29917
|
const image = _.clone(this.props.backgroundImage);
|
|
@@ -29950,7 +29922,7 @@ class InteractiveGraphSettings extends React.Component {
|
|
|
29950
29922
|
},
|
|
29951
29923
|
onKeyPress: this.changeBackgroundUrl,
|
|
29952
29924
|
onBlur: this.changeBackgroundUrl
|
|
29953
|
-
}), /*#__PURE__*/React.createElement(InfoTip$c, null, /*#__PURE__*/React.createElement("p", null, "Create an image in graphie, or use the \"Add image\" function to create a background.")))),
|
|
29925
|
+
}), /*#__PURE__*/React.createElement(InfoTip$c, null, /*#__PURE__*/React.createElement("p", null, "Create an image in graphie, or use the \"Add image\" function to create a background.")))), /*#__PURE__*/React.createElement("div", {
|
|
29954
29926
|
className: "misc-settings"
|
|
29955
29927
|
}, /*#__PURE__*/React.createElement("div", {
|
|
29956
29928
|
className: "perseus-widget-row"
|
|
@@ -29980,13 +29952,13 @@ class InteractiveGraphSettings extends React.Component {
|
|
|
29980
29952
|
value: this.props.rulerTicks
|
|
29981
29953
|
}, _.map([1, 2, 4, 8, 10, 16], function (n) {
|
|
29982
29954
|
return /*#__PURE__*/React.createElement("option", {
|
|
29955
|
+
key: `ruler-tick-${n}`,
|
|
29983
29956
|
value: n
|
|
29984
29957
|
}, n);
|
|
29985
29958
|
})))))));
|
|
29986
29959
|
}
|
|
29987
29960
|
}
|
|
29988
29961
|
InteractiveGraphSettings.defaultProps = {
|
|
29989
|
-
editableSettings: ["graph", "snap", "image", "measure"],
|
|
29990
29962
|
box: [interactiveSizes.defaultBoxSizeSmall, interactiveSizes.defaultBoxSizeSmall],
|
|
29991
29963
|
labels: ["x", "y"],
|
|
29992
29964
|
range: [[-10, 10], [-10, 10]],
|
|
@@ -30097,6 +30069,7 @@ class InteractiveGraphEditor extends React.Component {
|
|
|
30097
30069
|
markings: this.props.markings,
|
|
30098
30070
|
showProtractor: this.props.showProtractor,
|
|
30099
30071
|
showRuler: this.props.showRuler,
|
|
30072
|
+
showTooltips: this.props.showTooltips,
|
|
30100
30073
|
rulerLabel: this.props.rulerLabel,
|
|
30101
30074
|
rulerTicks: this.props.rulerTicks,
|
|
30102
30075
|
trackInteraction: function () {},
|