@khanacademy/perseus-editor 6.0.1 → 6.0.3
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/es/index.js +89 -91
- package/dist/es/index.js.map +1 -1
- package/dist/index.js +36 -29
- package/dist/index.js.map +1 -1
- package/dist/widgets/numeric-input-editor.d.ts +9 -9
- package/package.json +2 -2
package/dist/es/index.js
CHANGED
|
@@ -29,7 +29,7 @@ import Button from '@khanacademy/wonder-blocks-button';
|
|
|
29
29
|
|
|
30
30
|
// This file is processed by a Rollup plugin (replace) to inject the production
|
|
31
31
|
const libName = "@khanacademy/perseus-editor";
|
|
32
|
-
const libVersion = "6.0.
|
|
32
|
+
const libVersion = "6.0.3";
|
|
33
33
|
addLibraryVersionToPerseusDebug(libName, libVersion);
|
|
34
34
|
|
|
35
35
|
function _extends() {
|
|
@@ -33380,6 +33380,94 @@ const initAnswer = status => {
|
|
|
33380
33380
|
class NumericInputEditor extends React.Component {
|
|
33381
33381
|
constructor(props) {
|
|
33382
33382
|
super(props);
|
|
33383
|
+
this.change = (...args) => {
|
|
33384
|
+
return Changeable.change.apply(this, args);
|
|
33385
|
+
};
|
|
33386
|
+
this.onToggleOptions = choiceIndex => {
|
|
33387
|
+
const showOptions = this.state.showOptions.slice();
|
|
33388
|
+
showOptions[choiceIndex] = !showOptions[choiceIndex];
|
|
33389
|
+
this.setState({
|
|
33390
|
+
showOptions: showOptions
|
|
33391
|
+
});
|
|
33392
|
+
};
|
|
33393
|
+
this.onTrashAnswer = choiceIndex => {
|
|
33394
|
+
if (choiceIndex >= 0 && choiceIndex < this.props.answers.length) {
|
|
33395
|
+
const answers = this.props.answers.slice(0);
|
|
33396
|
+
answers.splice(choiceIndex, 1);
|
|
33397
|
+
this.props.onChange({
|
|
33398
|
+
answers: answers
|
|
33399
|
+
});
|
|
33400
|
+
}
|
|
33401
|
+
};
|
|
33402
|
+
this.onSpace = (e, callback, ...args) => {
|
|
33403
|
+
if (e.key === " ") {
|
|
33404
|
+
e.preventDefault(); // prevent page shifting
|
|
33405
|
+
callback.apply(this, args);
|
|
33406
|
+
}
|
|
33407
|
+
};
|
|
33408
|
+
this.onStatusChange = choiceIndex => {
|
|
33409
|
+
const statuses = ["wrong", "ungraded", "correct"];
|
|
33410
|
+
const answers = this.props.answers;
|
|
33411
|
+
const i = _.indexOf(statuses, answers[choiceIndex].status);
|
|
33412
|
+
const newStatus = statuses[(i + 1) % statuses.length];
|
|
33413
|
+
this.updateAnswer(choiceIndex, {
|
|
33414
|
+
status: newStatus,
|
|
33415
|
+
simplify: newStatus === "correct" ? "required" : "accepted"
|
|
33416
|
+
});
|
|
33417
|
+
};
|
|
33418
|
+
this.updateAnswer = (choiceIndex, update) => {
|
|
33419
|
+
if (!_.isObject(update)) {
|
|
33420
|
+
return _.partial((choiceIndex, key, value) => {
|
|
33421
|
+
const update = {};
|
|
33422
|
+
update[key] = value;
|
|
33423
|
+
this.updateAnswer(choiceIndex, update);
|
|
33424
|
+
}, choiceIndex, update);
|
|
33425
|
+
}
|
|
33426
|
+
let answers = [
|
|
33427
|
+
// Have to do this to remove the `readonly` state from the prop
|
|
33428
|
+
...this.props.answers];
|
|
33429
|
+
|
|
33430
|
+
// Don't bother to make a new answer box unless we are editing the last
|
|
33431
|
+
// one.
|
|
33432
|
+
// TODO(oliver): This might not be necessary anymore.
|
|
33433
|
+
if (choiceIndex === answers.length) {
|
|
33434
|
+
const lastAnswer = initAnswer(this.state.lastStatus);
|
|
33435
|
+
answers = answers.concat(lastAnswer);
|
|
33436
|
+
}
|
|
33437
|
+
answers[choiceIndex] = _.extend({}, answers[choiceIndex], update);
|
|
33438
|
+
this.props.onChange({
|
|
33439
|
+
answers: answers
|
|
33440
|
+
});
|
|
33441
|
+
};
|
|
33442
|
+
this.addAnswer = () => {
|
|
33443
|
+
const lastAnswer = initAnswer(this.state.lastStatus);
|
|
33444
|
+
const answers = this.props.answers.concat(lastAnswer);
|
|
33445
|
+
this.props.onChange({
|
|
33446
|
+
answers: answers
|
|
33447
|
+
});
|
|
33448
|
+
};
|
|
33449
|
+
this.getSaveWarnings = () => {
|
|
33450
|
+
// Filter out all the empty answers
|
|
33451
|
+
const warnings = [];
|
|
33452
|
+
// TODO(emily): This doesn't actually work, because the value is either
|
|
33453
|
+
// null or undefined when undefined, probably.
|
|
33454
|
+
if (_.contains(_.pluck(this.props.answers, "value"), "")) {
|
|
33455
|
+
// @ts-expect-error - TS2345 - Argument of type 'string' is not assignable to parameter of type 'never'.
|
|
33456
|
+
warnings.push("One or more answers is empty");
|
|
33457
|
+
}
|
|
33458
|
+
this.props.answers.forEach((answer, i) => {
|
|
33459
|
+
const formatError = answer.strict && (!answer.answerForms || answer.answerForms.length === 0);
|
|
33460
|
+
if (formatError) {
|
|
33461
|
+
warnings.push(
|
|
33462
|
+
// @ts-expect-error - TS2345 - Argument of type 'string' is not assignable to parameter of type 'never'.
|
|
33463
|
+
`Answer ${i + 1} is set to string format ` + "matching, but no format was selected");
|
|
33464
|
+
}
|
|
33465
|
+
});
|
|
33466
|
+
return warnings;
|
|
33467
|
+
};
|
|
33468
|
+
this.serialize = () => {
|
|
33469
|
+
return EditorJsonify.serialize.call(this);
|
|
33470
|
+
};
|
|
33383
33471
|
this.state = {
|
|
33384
33472
|
lastStatus: "wrong",
|
|
33385
33473
|
showOptions: _.map(this.props.answers, () => false)
|
|
@@ -33576,96 +33664,6 @@ class NumericInputEditor extends React.Component {
|
|
|
33576
33664
|
className: "msg-title"
|
|
33577
33665
|
}, "Message shown to user on attempt"), generateInputAnswerEditors(), addAnswerButton, inputSize, rightAlign, coefficientCheck, labelText);
|
|
33578
33666
|
}
|
|
33579
|
-
change(...args) {
|
|
33580
|
-
return Changeable.change.apply(this, args);
|
|
33581
|
-
}
|
|
33582
|
-
onToggleOptions(choiceIndex) {
|
|
33583
|
-
const showOptions = this.state.showOptions.slice();
|
|
33584
|
-
showOptions[choiceIndex] = !showOptions[choiceIndex];
|
|
33585
|
-
this.setState({
|
|
33586
|
-
showOptions: showOptions
|
|
33587
|
-
});
|
|
33588
|
-
}
|
|
33589
|
-
onTrashAnswer(choiceIndex) {
|
|
33590
|
-
if (choiceIndex >= 0 && choiceIndex < this.props.answers.length) {
|
|
33591
|
-
const answers = this.props.answers.slice(0);
|
|
33592
|
-
answers.splice(choiceIndex, 1);
|
|
33593
|
-
this.props.onChange({
|
|
33594
|
-
answers: answers
|
|
33595
|
-
});
|
|
33596
|
-
}
|
|
33597
|
-
}
|
|
33598
|
-
onSpace(e, callback) {
|
|
33599
|
-
if (e.key === " ") {
|
|
33600
|
-
e.preventDefault(); // prevent page shifting
|
|
33601
|
-
// eslint-disable-next-line prefer-rest-params
|
|
33602
|
-
const args = _.toArray(arguments).slice(2);
|
|
33603
|
-
callback.apply(this, args);
|
|
33604
|
-
}
|
|
33605
|
-
}
|
|
33606
|
-
onStatusChange(choiceIndex) {
|
|
33607
|
-
const statuses = ["wrong", "ungraded", "correct"];
|
|
33608
|
-
const answers = this.props.answers;
|
|
33609
|
-
const i = _.indexOf(statuses, answers[choiceIndex].status);
|
|
33610
|
-
const newStatus = statuses[(i + 1) % statuses.length];
|
|
33611
|
-
this.updateAnswer(choiceIndex, {
|
|
33612
|
-
status: newStatus,
|
|
33613
|
-
simplify: newStatus === "correct" ? "required" : "accepted"
|
|
33614
|
-
});
|
|
33615
|
-
}
|
|
33616
|
-
updateAnswer(choiceIndex, update) {
|
|
33617
|
-
if (!_.isObject(update)) {
|
|
33618
|
-
return _.partial((choiceIndex, key, value) => {
|
|
33619
|
-
const update = {};
|
|
33620
|
-
update[key] = value;
|
|
33621
|
-
this.updateAnswer(choiceIndex, update);
|
|
33622
|
-
}, choiceIndex, update);
|
|
33623
|
-
}
|
|
33624
|
-
let answers = [
|
|
33625
|
-
// Have to do this to remove the `readonly` state from the prop
|
|
33626
|
-
...this.props.answers];
|
|
33627
|
-
|
|
33628
|
-
// Don't bother to make a new answer box unless we are editing the last
|
|
33629
|
-
// one.
|
|
33630
|
-
// TODO(oliver): This might not be necessary anymore.
|
|
33631
|
-
if (choiceIndex === answers.length) {
|
|
33632
|
-
const lastAnswer = initAnswer(this.state.lastStatus);
|
|
33633
|
-
answers = answers.concat(lastAnswer);
|
|
33634
|
-
}
|
|
33635
|
-
answers[choiceIndex] = _.extend({}, answers[choiceIndex], update);
|
|
33636
|
-
this.props.onChange({
|
|
33637
|
-
answers: answers
|
|
33638
|
-
});
|
|
33639
|
-
}
|
|
33640
|
-
addAnswer() {
|
|
33641
|
-
const lastAnswer = initAnswer(this.state.lastStatus);
|
|
33642
|
-
const answers = this.props.answers.concat(lastAnswer);
|
|
33643
|
-
this.props.onChange({
|
|
33644
|
-
answers: answers
|
|
33645
|
-
});
|
|
33646
|
-
}
|
|
33647
|
-
getSaveWarnings() {
|
|
33648
|
-
// Filter out all the empty answers
|
|
33649
|
-
const warnings = [];
|
|
33650
|
-
// TODO(emily): This doesn't actually work, because the value is either
|
|
33651
|
-
// null or undefined when undefined, probably.
|
|
33652
|
-
if (_.contains(_.pluck(this.props.answers, "value"), "")) {
|
|
33653
|
-
// @ts-expect-error - TS2345 - Argument of type 'string' is not assignable to parameter of type 'never'.
|
|
33654
|
-
warnings.push("One or more answers is empty");
|
|
33655
|
-
}
|
|
33656
|
-
this.props.answers.forEach((answer, i) => {
|
|
33657
|
-
const formatError = answer.strict && (!answer.answerForms || answer.answerForms.length === 0);
|
|
33658
|
-
if (formatError) {
|
|
33659
|
-
warnings.push(
|
|
33660
|
-
// @ts-expect-error - TS2345 - Argument of type 'string' is not assignable to parameter of type 'never'.
|
|
33661
|
-
`Answer ${i + 1} is set to string format ` + "matching, but no format was selected");
|
|
33662
|
-
}
|
|
33663
|
-
});
|
|
33664
|
-
return warnings;
|
|
33665
|
-
}
|
|
33666
|
-
serialize() {
|
|
33667
|
-
return EditorJsonify.serialize.call(this);
|
|
33668
|
-
}
|
|
33669
33667
|
}
|
|
33670
33668
|
NumericInputEditor.contextType = PerseusI18nContext;
|
|
33671
33669
|
NumericInputEditor.widgetName = "numeric-input";
|