@khanacademy/perseus-editor 4.2.4 → 4.2.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.
- package/dist/components/graph-settings.d.ts +1 -84
- package/dist/es/index.js +95 -82
- package/dist/es/index.js.map +1 -1
- package/dist/index.js +96 -81
- package/dist/index.js.map +1 -1
- package/dist/widgets/interaction-editor/interaction-editor.d.ts +1 -1
- package/dist/widgets/interactive-graph-editor.d.ts +2 -2
- package/package.json +3 -3
|
@@ -1,85 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import type { PerseusImageBackground } from "@khanacademy/perseus";
|
|
3
|
-
type EditableSetting = "canvas" | "graph" | "snap" | "image" | "measure";
|
|
4
|
-
type Props = {
|
|
5
|
-
editableSettings: ReadonlyArray<EditableSetting>;
|
|
6
|
-
box: [number, number];
|
|
7
|
-
labels: ReadonlyArray<string>;
|
|
8
|
-
range: [[number, number], [number, number]];
|
|
9
|
-
step: [number, number];
|
|
10
|
-
gridStep: [number, number];
|
|
11
|
-
snapStep: [number, number];
|
|
12
|
-
valid: boolean | string;
|
|
13
|
-
backgroundImage: PerseusImageBackground;
|
|
14
|
-
markings: "graph" | "grid" | "none";
|
|
15
|
-
showProtractor: boolean;
|
|
16
|
-
showRuler: boolean;
|
|
17
|
-
showTooltips: boolean;
|
|
18
|
-
rulerLabel: string;
|
|
19
|
-
rulerTicks: number;
|
|
20
|
-
onChange: (arg1: Partial<Props>) => void;
|
|
21
|
-
};
|
|
22
|
-
type State = {
|
|
23
|
-
labelsTextbox: ReadonlyArray<string>;
|
|
24
|
-
gridStepTextbox: [number, number];
|
|
25
|
-
snapStepTextbox: [number, number];
|
|
26
|
-
stepTextbox: [number, number];
|
|
27
|
-
rangeTextbox: [[number, number], [number, number]];
|
|
28
|
-
backgroundImage: PerseusImageBackground;
|
|
29
|
-
};
|
|
30
|
-
declare class GraphSettings extends React.Component<Props, State> {
|
|
31
|
-
_isMounted: boolean;
|
|
32
|
-
static stateFromProps(props: any): {
|
|
33
|
-
labelsTextbox: any;
|
|
34
|
-
gridStepTextbox: any;
|
|
35
|
-
snapStepTextbox: any;
|
|
36
|
-
stepTextbox: any;
|
|
37
|
-
rangeTextbox: any;
|
|
38
|
-
backgroundImage: any;
|
|
39
|
-
};
|
|
40
|
-
constructor(props: Props);
|
|
41
|
-
static defaultProps: {
|
|
42
|
-
editableSettings: string[];
|
|
43
|
-
box: 288[];
|
|
44
|
-
labels: string[];
|
|
45
|
-
range: number[][];
|
|
46
|
-
step: number[];
|
|
47
|
-
gridStep: number[];
|
|
48
|
-
snapStep: number[];
|
|
49
|
-
valid: boolean;
|
|
50
|
-
backgroundImage: {
|
|
51
|
-
readonly url: null;
|
|
52
|
-
readonly width: 0;
|
|
53
|
-
readonly height: 0;
|
|
54
|
-
};
|
|
55
|
-
markings: string;
|
|
56
|
-
showProtractor: boolean;
|
|
57
|
-
showRuler: boolean;
|
|
58
|
-
showTooltips: boolean;
|
|
59
|
-
rulerLabel: string;
|
|
60
|
-
rulerTicks: number;
|
|
61
|
-
};
|
|
62
|
-
componentDidMount(): void;
|
|
63
|
-
UNSAFE_componentWillReceiveProps(nextProps: any): void;
|
|
64
|
-
componentWillUnmount(): void;
|
|
65
|
-
change(...args: any[]): any;
|
|
66
|
-
changeRulerLabel(e: any): void;
|
|
67
|
-
changeRulerTicks(e: any): void;
|
|
68
|
-
changeBackgroundUrl(e: any): void;
|
|
69
|
-
renderLabelChoices(choices: any): JSX.Element[];
|
|
70
|
-
validRange(range: any): true | "Range must be a valid number" | "Range must have a higher number on the right";
|
|
71
|
-
validateStepValue(settings: any): string | true;
|
|
72
|
-
validSnapStep(step: any, range: any): string | true;
|
|
73
|
-
validGridStep(step: any, range: any): string | true;
|
|
74
|
-
validStep(step: any, range: any): string | true;
|
|
75
|
-
validBackgroundImageSize(image: any): true | "Image must be smaller than 450px x 450px.";
|
|
76
|
-
validateGraphSettings(range: any, step: any, gridStep: any, snapStep: any, image: any): any;
|
|
77
|
-
changeLabel(i: any, e: any): void;
|
|
78
|
-
changeRange(i: any, values: any): void;
|
|
79
|
-
changeStep(step: any): void;
|
|
80
|
-
changeSnapStep(snapStep: any): void;
|
|
81
|
-
changeGridStep(gridStep: any): void;
|
|
82
|
-
changeGraph(): void;
|
|
83
|
-
render(): JSX.Element;
|
|
84
|
-
}
|
|
1
|
+
declare const GraphSettings: any;
|
|
85
2
|
export default GraphSettings;
|
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 = "4.2.
|
|
28
|
+
const libVersion = "4.2.6";
|
|
29
29
|
addLibraryVersionToPerseusDebug(libName, libVersion);
|
|
30
30
|
|
|
31
31
|
function _extends() {
|
|
@@ -27170,7 +27170,6 @@ GradedGroupSetEditor.defaultProps = {
|
|
|
27170
27170
|
};
|
|
27171
27171
|
const setArrayItem = (list, i, value) => [...list.slice(0, i), value, ...list.slice(i + 1)];
|
|
27172
27172
|
|
|
27173
|
-
/* eslint-disable react/forbid-prop-types, react/no-unsafe */
|
|
27174
27173
|
const {
|
|
27175
27174
|
ButtonGroup: ButtonGroup$3,
|
|
27176
27175
|
InfoTip: InfoTip$h,
|
|
@@ -27188,55 +27187,89 @@ const defaultBackgroundImage$2 = {
|
|
|
27188
27187
|
function numSteps(range, step) {
|
|
27189
27188
|
return Math.floor((range[1] - range[0]) / step);
|
|
27190
27189
|
}
|
|
27191
|
-
|
|
27192
|
-
|
|
27190
|
+
const GraphSettings = createReactClass({
|
|
27191
|
+
displayName: "GraphSettings",
|
|
27192
|
+
propTypes: _extends({}, Changeable.propTypes, {
|
|
27193
|
+
editableSettings: PropTypes.arrayOf(PropTypes.oneOf(["canvas", "graph", "snap", "image", "measure"])),
|
|
27194
|
+
box: PropTypes.arrayOf(PropTypes.number),
|
|
27195
|
+
labels: PropTypes.arrayOf(PropTypes.string),
|
|
27196
|
+
range: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.number)),
|
|
27197
|
+
step: PropTypes.arrayOf(PropTypes.number),
|
|
27198
|
+
gridStep: PropTypes.arrayOf(PropTypes.number),
|
|
27199
|
+
snapStep: PropTypes.arrayOf(PropTypes.number),
|
|
27200
|
+
valid: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
|
|
27201
|
+
backgroundImage: PropTypes.object,
|
|
27202
|
+
markings: PropTypes.oneOf(["graph", "grid", "none"]),
|
|
27203
|
+
showProtractor: PropTypes.bool,
|
|
27204
|
+
showRuler: PropTypes.bool,
|
|
27205
|
+
showTooltips: PropTypes.bool,
|
|
27206
|
+
rulerLabel: PropTypes.string,
|
|
27207
|
+
rulerTicks: PropTypes.number
|
|
27208
|
+
}),
|
|
27209
|
+
getDefaultProps: function () {
|
|
27193
27210
|
return {
|
|
27194
|
-
|
|
27195
|
-
|
|
27196
|
-
|
|
27197
|
-
|
|
27198
|
-
|
|
27199
|
-
|
|
27211
|
+
editableSettings: ["graph", "snap", "image", "measure"],
|
|
27212
|
+
box: [interactiveSizes.defaultBoxSizeSmall, interactiveSizes.defaultBoxSizeSmall],
|
|
27213
|
+
labels: ["x", "y"],
|
|
27214
|
+
range: [[-10, 10], [-10, 10]],
|
|
27215
|
+
step: [1, 1],
|
|
27216
|
+
gridStep: [1, 1],
|
|
27217
|
+
snapStep: [1, 1],
|
|
27218
|
+
valid: true,
|
|
27219
|
+
backgroundImage: defaultBackgroundImage$2,
|
|
27220
|
+
markings: "graph",
|
|
27221
|
+
showProtractor: false,
|
|
27222
|
+
showRuler: false,
|
|
27223
|
+
showTooltips: false,
|
|
27224
|
+
rulerLabel: "",
|
|
27225
|
+
rulerTicks: 10
|
|
27200
27226
|
};
|
|
27201
|
-
}
|
|
27202
|
-
|
|
27203
|
-
|
|
27204
|
-
|
|
27205
|
-
|
|
27206
|
-
}
|
|
27207
|
-
componentDidMount() {
|
|
27227
|
+
},
|
|
27228
|
+
getInitialState: function () {
|
|
27229
|
+
return this.stateFromProps(this.props);
|
|
27230
|
+
},
|
|
27231
|
+
componentDidMount: function () {
|
|
27208
27232
|
// TODO(scottgrant): This is a hack to remove the deprecated call to
|
|
27209
27233
|
// this.isMounted() but is still considered an anti-pattern.
|
|
27210
27234
|
this._isMounted = true;
|
|
27211
27235
|
this.changeGraph = _.debounce(this.changeGraph, 300);
|
|
27212
|
-
}
|
|
27213
|
-
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
27236
|
+
},
|
|
27237
|
+
UNSAFE_componentWillReceiveProps: function (nextProps) {
|
|
27214
27238
|
// Make sure that state updates when switching
|
|
27215
27239
|
// between different items in a multi-item editor.
|
|
27216
27240
|
if (!_.isEqual(this.props.labels, nextProps.labels) || !_.isEqual(this.props.gridStep, nextProps.gridStep) || !_.isEqual(this.props.snapStep, nextProps.snapStep) || !_.isEqual(this.props.step, nextProps.step) || !_.isEqual(this.props.range, nextProps.range) || !_.isEqual(this.props.backgroundImage, nextProps.backgroundImage)) {
|
|
27217
|
-
this.setState(
|
|
27241
|
+
this.setState(this.stateFromProps(nextProps));
|
|
27218
27242
|
}
|
|
27219
|
-
}
|
|
27220
|
-
componentWillUnmount() {
|
|
27243
|
+
},
|
|
27244
|
+
componentWillUnmount: function () {
|
|
27221
27245
|
this._isMounted = false;
|
|
27222
|
-
}
|
|
27246
|
+
},
|
|
27247
|
+
stateFromProps: function (props) {
|
|
27248
|
+
return {
|
|
27249
|
+
labelsTextbox: props.labels,
|
|
27250
|
+
gridStepTextbox: props.gridStep,
|
|
27251
|
+
snapStepTextbox: props.snapStep,
|
|
27252
|
+
stepTextbox: props.step,
|
|
27253
|
+
rangeTextbox: props.range,
|
|
27254
|
+
backgroundImage: _.clone(props.backgroundImage)
|
|
27255
|
+
};
|
|
27256
|
+
},
|
|
27223
27257
|
change(...args) {
|
|
27224
27258
|
return Changeable.change.apply(this, args);
|
|
27225
|
-
}
|
|
27226
|
-
|
|
27259
|
+
},
|
|
27227
27260
|
// TODO(aria): Make either a wrapper for standard events to work
|
|
27228
27261
|
// with this.change, or make these use some TextInput/NumberInput box
|
|
27229
|
-
changeRulerLabel(e) {
|
|
27262
|
+
changeRulerLabel: function (e) {
|
|
27230
27263
|
this.change({
|
|
27231
27264
|
rulerLabel: e.target.value
|
|
27232
27265
|
});
|
|
27233
|
-
}
|
|
27234
|
-
changeRulerTicks(e) {
|
|
27266
|
+
},
|
|
27267
|
+
changeRulerTicks: function (e) {
|
|
27235
27268
|
this.change({
|
|
27236
27269
|
rulerTicks: +e.target.value
|
|
27237
27270
|
});
|
|
27238
|
-
}
|
|
27239
|
-
changeBackgroundUrl(e) {
|
|
27271
|
+
},
|
|
27272
|
+
changeBackgroundUrl: function (e) {
|
|
27240
27273
|
// Only continue on blur or "enter"
|
|
27241
27274
|
if (e.type === "keypress" && e.key !== "Enter") {
|
|
27242
27275
|
return;
|
|
@@ -27262,15 +27295,15 @@ class GraphSettings extends React.Component {
|
|
|
27262
27295
|
} else {
|
|
27263
27296
|
setUrl(null, 0, 0);
|
|
27264
27297
|
}
|
|
27265
|
-
}
|
|
27266
|
-
renderLabelChoices(choices) {
|
|
27298
|
+
},
|
|
27299
|
+
renderLabelChoices: function (choices) {
|
|
27267
27300
|
return _.map(choices, function (nameAndValue) {
|
|
27268
27301
|
return /*#__PURE__*/React.createElement("option", {
|
|
27269
27302
|
value: nameAndValue[1]
|
|
27270
27303
|
}, nameAndValue[0]);
|
|
27271
27304
|
});
|
|
27272
|
-
}
|
|
27273
|
-
validRange(range) {
|
|
27305
|
+
},
|
|
27306
|
+
validRange: function (range) {
|
|
27274
27307
|
const numbers = _.every(range, function (num) {
|
|
27275
27308
|
return _.isFinite(num);
|
|
27276
27309
|
});
|
|
@@ -27281,8 +27314,8 @@ class GraphSettings extends React.Component {
|
|
|
27281
27314
|
return "Range must have a higher number on the right";
|
|
27282
27315
|
}
|
|
27283
27316
|
return true;
|
|
27284
|
-
}
|
|
27285
|
-
validateStepValue(settings) {
|
|
27317
|
+
},
|
|
27318
|
+
validateStepValue: function (settings) {
|
|
27286
27319
|
const {
|
|
27287
27320
|
step,
|
|
27288
27321
|
range,
|
|
@@ -27301,8 +27334,8 @@ class GraphSettings extends React.Component {
|
|
|
27301
27334
|
return name + " is too small, there can be at most " + maxTicks + " ticks.";
|
|
27302
27335
|
}
|
|
27303
27336
|
return true;
|
|
27304
|
-
}
|
|
27305
|
-
validSnapStep(step, range) {
|
|
27337
|
+
},
|
|
27338
|
+
validSnapStep: function (step, range) {
|
|
27306
27339
|
return this.validateStepValue({
|
|
27307
27340
|
step: step,
|
|
27308
27341
|
range: range,
|
|
@@ -27310,8 +27343,8 @@ class GraphSettings extends React.Component {
|
|
|
27310
27343
|
minTicks: 5,
|
|
27311
27344
|
maxTicks: 60
|
|
27312
27345
|
});
|
|
27313
|
-
}
|
|
27314
|
-
validGridStep(step, range) {
|
|
27346
|
+
},
|
|
27347
|
+
validGridStep: function (step, range) {
|
|
27315
27348
|
return this.validateStepValue({
|
|
27316
27349
|
step: step,
|
|
27317
27350
|
range: range,
|
|
@@ -27319,8 +27352,8 @@ class GraphSettings extends React.Component {
|
|
|
27319
27352
|
minTicks: 3,
|
|
27320
27353
|
maxTicks: 60
|
|
27321
27354
|
});
|
|
27322
|
-
}
|
|
27323
|
-
validStep(step, range) {
|
|
27355
|
+
},
|
|
27356
|
+
validStep: function (step, range) {
|
|
27324
27357
|
return this.validateStepValue({
|
|
27325
27358
|
step: step,
|
|
27326
27359
|
range: range,
|
|
@@ -27328,8 +27361,8 @@ class GraphSettings extends React.Component {
|
|
|
27328
27361
|
minTicks: 3,
|
|
27329
27362
|
maxTicks: 20
|
|
27330
27363
|
});
|
|
27331
|
-
}
|
|
27332
|
-
validBackgroundImageSize(image) {
|
|
27364
|
+
},
|
|
27365
|
+
validBackgroundImageSize: function (image) {
|
|
27333
27366
|
// Ignore empty images
|
|
27334
27367
|
if (!image.url) {
|
|
27335
27368
|
return true;
|
|
@@ -27339,8 +27372,8 @@ class GraphSettings extends React.Component {
|
|
|
27339
27372
|
return "Image must be smaller than 450px x 450px.";
|
|
27340
27373
|
}
|
|
27341
27374
|
return true;
|
|
27342
|
-
}
|
|
27343
|
-
validateGraphSettings(range, step, gridStep, snapStep, image) {
|
|
27375
|
+
},
|
|
27376
|
+
validateGraphSettings: function (range, step, gridStep, snapStep, image) {
|
|
27344
27377
|
const self = this;
|
|
27345
27378
|
let msg;
|
|
27346
27379
|
const goodRange = _.every(range, function (range) {
|
|
@@ -27377,16 +27410,16 @@ class GraphSettings extends React.Component {
|
|
|
27377
27410
|
return msg;
|
|
27378
27411
|
}
|
|
27379
27412
|
return true;
|
|
27380
|
-
}
|
|
27381
|
-
changeLabel(i, e) {
|
|
27413
|
+
},
|
|
27414
|
+
changeLabel: function (i, e) {
|
|
27382
27415
|
const val = e.target.value;
|
|
27383
27416
|
const labels = this.state.labelsTextbox.slice();
|
|
27384
27417
|
labels[i] = val;
|
|
27385
27418
|
this.setState({
|
|
27386
27419
|
labelsTextbox: labels
|
|
27387
27420
|
}, this.changeGraph);
|
|
27388
|
-
}
|
|
27389
|
-
changeRange(i, values) {
|
|
27421
|
+
},
|
|
27422
|
+
changeRange: function (i, values) {
|
|
27390
27423
|
const ranges = this.state.rangeTextbox.slice();
|
|
27391
27424
|
ranges[i] = values;
|
|
27392
27425
|
const step = this.state.stepTextbox.slice();
|
|
@@ -27395,10 +27428,7 @@ class GraphSettings extends React.Component {
|
|
|
27395
27428
|
const scale = Util.scaleFromExtent(ranges[i], this.props.box[i]);
|
|
27396
27429
|
if (this.validRange(ranges[i]) === true) {
|
|
27397
27430
|
step[i] = Util.tickStepFromExtent(ranges[i], this.props.box[i]);
|
|
27398
|
-
|
|
27399
|
-
if (gridStepValue) {
|
|
27400
|
-
gridStep[i] = gridStepValue;
|
|
27401
|
-
}
|
|
27431
|
+
gridStep[i] = Util.gridStepFromTickStep(step[i], scale);
|
|
27402
27432
|
snapStep[i] = gridStep[i] / 2;
|
|
27403
27433
|
}
|
|
27404
27434
|
this.setState({
|
|
@@ -27407,26 +27437,26 @@ class GraphSettings extends React.Component {
|
|
|
27407
27437
|
snapStepTextbox: snapStep,
|
|
27408
27438
|
rangeTextbox: ranges
|
|
27409
27439
|
}, this.changeGraph);
|
|
27410
|
-
}
|
|
27411
|
-
changeStep(step) {
|
|
27440
|
+
},
|
|
27441
|
+
changeStep: function (step) {
|
|
27412
27442
|
this.setState({
|
|
27413
27443
|
stepTextbox: step
|
|
27414
27444
|
}, this.changeGraph);
|
|
27415
|
-
}
|
|
27416
|
-
changeSnapStep(snapStep) {
|
|
27445
|
+
},
|
|
27446
|
+
changeSnapStep: function (snapStep) {
|
|
27417
27447
|
this.setState({
|
|
27418
27448
|
snapStepTextbox: snapStep
|
|
27419
27449
|
}, this.changeGraph);
|
|
27420
|
-
}
|
|
27421
|
-
changeGridStep(gridStep) {
|
|
27450
|
+
},
|
|
27451
|
+
changeGridStep: function (gridStep) {
|
|
27422
27452
|
this.setState({
|
|
27423
27453
|
gridStepTextbox: gridStep,
|
|
27424
27454
|
snapStepTextbox: _.map(gridStep, function (step) {
|
|
27425
27455
|
return step / 2;
|
|
27426
27456
|
})
|
|
27427
27457
|
}, this.changeGraph);
|
|
27428
|
-
}
|
|
27429
|
-
changeGraph() {
|
|
27458
|
+
},
|
|
27459
|
+
changeGraph: function () {
|
|
27430
27460
|
const labels = this.state.labelsTextbox;
|
|
27431
27461
|
const range = _.map(this.state.rangeTextbox, function (range) {
|
|
27432
27462
|
return _.map(range, Number);
|
|
@@ -27458,9 +27488,9 @@ class GraphSettings extends React.Component {
|
|
|
27458
27488
|
valid: validationResult // a string message, not false
|
|
27459
27489
|
});
|
|
27460
27490
|
}
|
|
27461
|
-
}
|
|
27491
|
+
},
|
|
27462
27492
|
|
|
27463
|
-
render() {
|
|
27493
|
+
render: function () {
|
|
27464
27494
|
const scale = [KhanMath.roundTo(2, Util.scaleFromExtent(this.props.range[0], this.props.box[0])), KhanMath.roundTo(2, Util.scaleFromExtent(this.props.range[1], this.props.box[1]))];
|
|
27465
27495
|
const {
|
|
27466
27496
|
TeX
|
|
@@ -27607,24 +27637,7 @@ class GraphSettings extends React.Component {
|
|
|
27607
27637
|
}, n);
|
|
27608
27638
|
})))))));
|
|
27609
27639
|
}
|
|
27610
|
-
}
|
|
27611
|
-
GraphSettings.defaultProps = {
|
|
27612
|
-
editableSettings: ["graph", "snap", "image", "measure"],
|
|
27613
|
-
box: [interactiveSizes.defaultBoxSizeSmall, interactiveSizes.defaultBoxSizeSmall],
|
|
27614
|
-
labels: ["x", "y"],
|
|
27615
|
-
range: [[-10, 10], [-10, 10]],
|
|
27616
|
-
step: [1, 1],
|
|
27617
|
-
gridStep: [1, 1],
|
|
27618
|
-
snapStep: [1, 1],
|
|
27619
|
-
valid: true,
|
|
27620
|
-
backgroundImage: defaultBackgroundImage$2,
|
|
27621
|
-
markings: "graph",
|
|
27622
|
-
showProtractor: false,
|
|
27623
|
-
showRuler: false,
|
|
27624
|
-
showTooltips: false,
|
|
27625
|
-
rulerLabel: "",
|
|
27626
|
-
rulerTicks: 10
|
|
27627
|
-
};
|
|
27640
|
+
});
|
|
27628
27641
|
|
|
27629
27642
|
const {
|
|
27630
27643
|
InfoTip: InfoTip$g,
|