@khanacademy/perseus 19.1.3 → 19.1.4
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/CHANGELOG.md +11 -0
- package/dist/es/index.js +25 -57
- package/dist/es/index.js.map +1 -1
- package/dist/index.js +38 -42
- package/dist/index.js.map +1 -1
- package/dist/interactive2/interactive-util.d.ts +1 -1
- package/dist/interactive2/movable.d.ts +20 -1
- package/dist/util/graphie.d.ts +1 -1
- package/package.json +2 -2
- package/src/interactive2/__tests__/movable-mock.ts +2 -1
- package/src/interactive2/__tests__/movable.test.ts +157 -0
- package/src/interactive2/interactive-util.test.ts +93 -0
- package/src/interactive2/interactive-util.ts +19 -15
- package/src/interactive2/movable-helper-methods.ts +7 -2
- package/src/interactive2/movable-line.ts +1 -12
- package/src/interactive2/movable-point.tsx +1 -9
- package/src/interactive2/movable-polygon.ts +1 -9
- package/src/interactive2/movable.ts +49 -44
- package/src/util/graphie.ts +3 -1
- package/tsconfig-build.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @khanacademy/perseus
|
|
2
2
|
|
|
3
|
+
## 19.1.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#958](https://github.com/Khan/perseus/pull/958) [`729b419a`](https://github.com/Khan/perseus/commit/729b419a5c31eaa6ac4da996a0683a2fdffc5997) Thanks [@benchristel](https://github.com/benchristel)! - Internal: Add tests for normalizeOptions function (used by Movable)
|
|
8
|
+
|
|
9
|
+
* [#960](https://github.com/Khan/perseus/pull/960) [`ce0227c1`](https://github.com/Khan/perseus/commit/ce0227c1d7b432b6a9484c32542ddf23d27b1e95) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Add tests for Movable pseudo-class
|
|
10
|
+
|
|
11
|
+
* Updated dependencies [[`a4a4dc44`](https://github.com/Khan/perseus/commit/a4a4dc447037eaea83423dc21a15076435c4b638)]:
|
|
12
|
+
- @khanacademy/math-input@17.0.3
|
|
13
|
+
|
|
3
14
|
## 19.1.3
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
package/dist/es/index.js
CHANGED
|
@@ -3985,8 +3985,10 @@ const MovableHelperMethods = {
|
|
|
3985
3985
|
/**
|
|
3986
3986
|
* Fire an onSomething type event to all functions in listeners
|
|
3987
3987
|
*/
|
|
3988
|
-
_fireEvent: function (listeners,
|
|
3989
|
-
|
|
3988
|
+
_fireEvent: function (listeners, ...args) {
|
|
3989
|
+
for (const listener of listeners) {
|
|
3990
|
+
listener.call(this, ...args);
|
|
3991
|
+
}
|
|
3990
3992
|
},
|
|
3991
3993
|
/**
|
|
3992
3994
|
* Combine the array of constraints functions
|
|
@@ -4086,10 +4088,6 @@ const MovableHelperMethods = {
|
|
|
4086
4088
|
}
|
|
4087
4089
|
};
|
|
4088
4090
|
|
|
4089
|
-
/**
|
|
4090
|
-
* Utility functions for writing Interactive2 movablethings
|
|
4091
|
-
*/
|
|
4092
|
-
|
|
4093
4091
|
/**
|
|
4094
4092
|
* Compute the correct vendor-prefixed `transform`.
|
|
4095
4093
|
*/
|
|
@@ -4123,6 +4121,7 @@ function computeCanUse3dTransform() {
|
|
|
4123
4121
|
// @ts-expect-error - TS2538 - Type 'null' cannot be used as an index type. | TS2538 - Type 'undefined' cannot be used as an index type.
|
|
4124
4122
|
return !!el.style[prefix];
|
|
4125
4123
|
}
|
|
4124
|
+
const FUNCTION_ARRAY_OPTIONS = ["add", "modify", "draw", "remove", "constraints", "onMoveStart", "onMove", "onMoveEnd", "onClick"];
|
|
4126
4125
|
const InteractiveUtil = {
|
|
4127
4126
|
assert: function (isTrue, message) {
|
|
4128
4127
|
if (!isTrue) {
|
|
@@ -4166,21 +4165,14 @@ const InteractiveUtil = {
|
|
|
4166
4165
|
/**
|
|
4167
4166
|
* Convert all function-or-array arguments to arrays of functions
|
|
4168
4167
|
*/
|
|
4169
|
-
normalizeOptions: function (
|
|
4170
|
-
|
|
4171
|
-
|
|
4172
|
-
// (and maybe be a function on MovableHelperMethods to get access
|
|
4173
|
-
// to this.state), which would also be nicer because we could
|
|
4174
|
-
// normalizeOptions once in this.modify
|
|
4175
|
-
const result = _.clone(options);
|
|
4176
|
-
_.each(arrayOptionNames, function (eventName) {
|
|
4177
|
-
const funcOrArray = options[eventName];
|
|
4168
|
+
normalizeOptions: function (options) {
|
|
4169
|
+
const result = _extends({}, options);
|
|
4170
|
+
FUNCTION_ARRAY_OPTIONS.forEach(function (eventName) {
|
|
4178
4171
|
// Only propagate values which were set; not present values
|
|
4179
4172
|
// shouldn't be added to options because we'd like them to
|
|
4180
4173
|
// fall through to defaults
|
|
4181
|
-
if (
|
|
4182
|
-
|
|
4183
|
-
result[eventName] = funcArray;
|
|
4174
|
+
if (options[eventName] !== undefined) {
|
|
4175
|
+
result[eventName] = InteractiveUtil.arrayify(options[eventName]);
|
|
4184
4176
|
}
|
|
4185
4177
|
});
|
|
4186
4178
|
return result;
|
|
@@ -8873,6 +8865,9 @@ class Graphie$1 {
|
|
|
8873
8865
|
var _options$isMobile;
|
|
8874
8866
|
let scale = options.scale || [40, 40];
|
|
8875
8867
|
scale = typeof scale === "number" ? [scale, scale] : scale;
|
|
8868
|
+
|
|
8869
|
+
// TODO(jeremy): This can be removed once we're confident that callers
|
|
8870
|
+
// obey the Typescript types.
|
|
8876
8871
|
if (options.range == null) {
|
|
8877
8872
|
throw new PerseusError("range should be specified in graph init", Errors.Internal);
|
|
8878
8873
|
}
|
|
@@ -13724,24 +13719,9 @@ var GraphieClasses = {
|
|
|
13724
13719
|
createSimpleClass: createSimpleClass
|
|
13725
13720
|
};
|
|
13726
13721
|
|
|
13727
|
-
/**
|
|
13728
|
-
* Movable
|
|
13729
|
-
*
|
|
13730
|
-
* A Movable Something, that sends onMove events based on the
|
|
13731
|
-
* mouse coordinate (graphie unscaled, non-pixel-value) of the
|
|
13732
|
-
* move.
|
|
13733
|
-
*
|
|
13734
|
-
* Other MovableThings should generally have a Movable field, and
|
|
13735
|
-
* let this class handle all of the virtual mouse events, and then
|
|
13736
|
-
* take appropriate action in onMoveStart, onMove, onMoveEnd
|
|
13737
|
-
*/
|
|
13738
13722
|
const normalizeOptions$3 = InteractiveUtil.normalizeOptions;
|
|
13739
13723
|
const assert$8 = InteractiveUtil.assert;
|
|
13740
13724
|
|
|
13741
|
-
// state parameters that should be converted into an array of
|
|
13742
|
-
// functions
|
|
13743
|
-
const FUNCTION_ARRAY_OPTIONS$3 = ["add", "modify", "draw", "remove", "onMoveStart", "onMove", "onMoveEnd", "onClick"];
|
|
13744
|
-
|
|
13745
13725
|
// Default "props" and "state". Both are added to this.state and
|
|
13746
13726
|
// receive magic getter methods (this.isHovering() etc).
|
|
13747
13727
|
// However, properties in DEFAULT_PROPS are updated on `modify()`,
|
|
@@ -13761,7 +13741,7 @@ const DEFAULT_STATE$3 = {
|
|
|
13761
13741
|
const Movable = function Movable(graphie, options) {
|
|
13762
13742
|
// @ts-expect-error - TS2683 - 'this' implicitly has type 'any' because it does not have a type annotation.
|
|
13763
13743
|
_.extend(this, {
|
|
13764
|
-
graphie
|
|
13744
|
+
graphie,
|
|
13765
13745
|
state: {
|
|
13766
13746
|
// Set here because this must be unique for each instance
|
|
13767
13747
|
id: _.uniqueId("movable")
|
|
@@ -13776,10 +13756,10 @@ InteractiveUtil.createGettersFor(Movable, _.extend({}, DEFAULT_PROPS$3, DEFAULT_
|
|
|
13776
13756
|
InteractiveUtil.addMovableHelperMethodsTo(Movable);
|
|
13777
13757
|
_.extend(Movable.prototype, {
|
|
13778
13758
|
cloneState: function () {
|
|
13779
|
-
return
|
|
13759
|
+
return _extends({}, this.state);
|
|
13780
13760
|
},
|
|
13781
13761
|
_createDefaultState: function () {
|
|
13782
|
-
return
|
|
13762
|
+
return _extends({
|
|
13783
13763
|
id: this.state.id,
|
|
13784
13764
|
add: [],
|
|
13785
13765
|
modify: [],
|
|
@@ -13789,9 +13769,6 @@ _.extend(Movable.prototype, {
|
|
|
13789
13769
|
onMove: [],
|
|
13790
13770
|
onMoveEnd: [],
|
|
13791
13771
|
onClick: []
|
|
13792
|
-
|
|
13793
|
-
// We only update props here, because we want things on state to
|
|
13794
|
-
// be persistent, and updated appropriately in modify()
|
|
13795
13772
|
}, DEFAULT_PROPS$3);
|
|
13796
13773
|
},
|
|
13797
13774
|
/**
|
|
@@ -13801,7 +13778,7 @@ _.extend(Movable.prototype, {
|
|
|
13801
13778
|
* Analogous to React.js's replaceProps
|
|
13802
13779
|
*/
|
|
13803
13780
|
modify: function (options) {
|
|
13804
|
-
this.update(
|
|
13781
|
+
this.update(_extends({}, this._createDefaultState(), options));
|
|
13805
13782
|
},
|
|
13806
13783
|
/**
|
|
13807
13784
|
* Simulates a mouse grab event on the movable object.
|
|
@@ -13849,7 +13826,7 @@ _.extend(Movable.prototype, {
|
|
|
13849
13826
|
const self = this;
|
|
13850
13827
|
const graphie = self.graphie;
|
|
13851
13828
|
const prevState = self.cloneState();
|
|
13852
|
-
const state = _.extend(self.state, normalizeOptions$3(
|
|
13829
|
+
const state = _.extend(self.state, normalizeOptions$3(options));
|
|
13853
13830
|
|
|
13854
13831
|
// the invisible shape in front of the point that gets mouse events
|
|
13855
13832
|
if (state.mouseTarget && !prevState.mouseTarget) {
|
|
@@ -14275,7 +14252,6 @@ var MovableLineOptions = {
|
|
|
14275
14252
|
*/
|
|
14276
14253
|
const assert$7 = InteractiveUtil.assert;
|
|
14277
14254
|
const normalizeOptions$2 = InteractiveUtil.normalizeOptions;
|
|
14278
|
-
const FUNCTION_ARRAY_OPTIONS$2 = ["add", "draw", "remove", "onMoveStart", "constraints", "onMove", "onMoveEnd"];
|
|
14279
14255
|
|
|
14280
14256
|
// Default "props" and "state". Both are added to this.state and
|
|
14281
14257
|
// receive magic getter methods (this.cursor() etc).
|
|
@@ -14328,7 +14304,7 @@ _.extend(MovableLine$4.prototype, {
|
|
|
14328
14304
|
_createDefaultState: function () {
|
|
14329
14305
|
return _.extend({
|
|
14330
14306
|
id: this.state.id
|
|
14331
|
-
}, normalizeOptions$2(
|
|
14307
|
+
}, normalizeOptions$2(
|
|
14332
14308
|
// Defaults are copied from MovableLineOptions.*.standard
|
|
14333
14309
|
// These defaults are set here instead of DEFAULT_PROPS/STATE
|
|
14334
14310
|
// because they:
|
|
@@ -14355,7 +14331,7 @@ _.extend(MovableLine$4.prototype, {
|
|
|
14355
14331
|
update: function (options) {
|
|
14356
14332
|
const self = this;
|
|
14357
14333
|
const graphie = this.graphie;
|
|
14358
|
-
const state = self.state = _.extend(self.state, normalizeOptions$2(
|
|
14334
|
+
const state = self.state = _.extend(self.state, normalizeOptions$2(options));
|
|
14359
14335
|
|
|
14360
14336
|
// Default things inside the state.normalStyle object, because
|
|
14361
14337
|
// _.extend is not deep.
|
|
@@ -14859,10 +14835,6 @@ const {
|
|
|
14859
14835
|
processMath
|
|
14860
14836
|
} = Tex$1;
|
|
14861
14837
|
|
|
14862
|
-
// State parameters that should be converted into an array of
|
|
14863
|
-
// functions
|
|
14864
|
-
const FUNCTION_ARRAY_OPTIONS$1 = _.keys(MovablePointOptions);
|
|
14865
|
-
|
|
14866
14838
|
// Default "props" and "state". Both are added to this.state and
|
|
14867
14839
|
// receive magic getter methods (this.coord() etc).
|
|
14868
14840
|
// However, properties in DEFAULT_PROPS are updated on `modify()`,
|
|
@@ -14915,7 +14887,7 @@ _.extend(MovablePoint$5.prototype, {
|
|
|
14915
14887
|
_createDefaultState: function () {
|
|
14916
14888
|
return _.extend({
|
|
14917
14889
|
id: this.state.id
|
|
14918
|
-
}, normalizeOptions$1(
|
|
14890
|
+
}, normalizeOptions$1(
|
|
14919
14891
|
// Defaults are copied from MovablePointOptions.*.standard
|
|
14920
14892
|
// These defaults are set here instead of DEFAULT_PROPS/STATE
|
|
14921
14893
|
// because they:
|
|
@@ -14988,7 +14960,7 @@ _.extend(MovablePoint$5.prototype, {
|
|
|
14988
14960
|
update: function (options) {
|
|
14989
14961
|
const self = this;
|
|
14990
14962
|
const graphie = self.graphie;
|
|
14991
|
-
const state = _.extend(self.state, normalizeOptions$1(
|
|
14963
|
+
const state = _.extend(self.state, normalizeOptions$1(options));
|
|
14992
14964
|
assert$6(point.is(state.coord));
|
|
14993
14965
|
|
|
14994
14966
|
// Default things inside the state.normalStyle object, because
|
|
@@ -15595,10 +15567,6 @@ var MovablePolygonOptions = {
|
|
|
15595
15567
|
const assert$5 = InteractiveUtil.assert;
|
|
15596
15568
|
const normalizeOptions = InteractiveUtil.normalizeOptions;
|
|
15597
15569
|
|
|
15598
|
-
// State parameters that should be converted into an array of
|
|
15599
|
-
// functions
|
|
15600
|
-
const FUNCTION_ARRAY_OPTIONS = _.keys(MovablePolygonOptions);
|
|
15601
|
-
|
|
15602
15570
|
// Default "props" and "state". Both are added to this.state and
|
|
15603
15571
|
// receive magic getter methods (this.points() etc).
|
|
15604
15572
|
// However, properties in DEFAULT_PROPS are updated on `modify()`,
|
|
@@ -15658,7 +15626,7 @@ _.extend(MovablePolygon.prototype, {
|
|
|
15658
15626
|
_createDefaultState: function () {
|
|
15659
15627
|
return _.extend({
|
|
15660
15628
|
id: this.state.id
|
|
15661
|
-
}, normalizeOptions(
|
|
15629
|
+
}, normalizeOptions(
|
|
15662
15630
|
// Defaults are copied from MovablePolygonOptions.*.standard
|
|
15663
15631
|
// These defaults are set here instead of DEFAULT_PROPS/STATE
|
|
15664
15632
|
// because they:
|
|
@@ -15689,7 +15657,7 @@ _.extend(MovablePolygon.prototype, {
|
|
|
15689
15657
|
update: function (options) {
|
|
15690
15658
|
const self = this;
|
|
15691
15659
|
const graphie = self.graphie;
|
|
15692
|
-
const state = _.extend(self.state, normalizeOptions(
|
|
15660
|
+
const state = _.extend(self.state, normalizeOptions(options));
|
|
15693
15661
|
|
|
15694
15662
|
// Default things inside the state.normalStyle object, because
|
|
15695
15663
|
// _.extend is not deep.
|
|
@@ -41499,7 +41467,7 @@ const init = function init(options) {
|
|
|
41499
41467
|
|
|
41500
41468
|
// This file is processed by a Rollup plugin (replace) to inject the production
|
|
41501
41469
|
const libName = "@khanacademy/perseus";
|
|
41502
|
-
const libVersion = "19.1.
|
|
41470
|
+
const libVersion = "19.1.4";
|
|
41503
41471
|
addLibraryVersionToPerseusDebug(libName, libVersion);
|
|
41504
41472
|
|
|
41505
41473
|
const apiVersion = {
|