@khanacademy/perseus 12.0.1 → 12.2.0
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 +21 -0
- package/dist/article-renderer.d.ts +2 -0
- package/dist/es/index.css +5 -2
- package/dist/es/index.js +36 -25
- package/dist/es/index.js.map +1 -1
- package/dist/index.css +5 -2
- package/dist/index.js +36 -25
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/__stories__/article-renderer.stories.tsx +28 -2
- package/src/__testdata__/article-renderer.testdata.ts +85 -0
- package/src/__tests__/article-renderer.test.tsx +131 -0
- package/src/__tests__/item-renderer.test.tsx +1 -19
- package/src/article-renderer.tsx +58 -45
- package/src/styles/perseus-renderer.less +1 -0
- package/src/styles/widgets/image.less +2 -6
- package/src/widgets/__stories__/image.stories.tsx +1 -0
- package/src/widgets/__tests__/__snapshots__/group.test.tsx.snap +1 -0
- package/src/widgets/__tests__/__snapshots__/image.test.ts.snap +2 -0
- package/src/widgets/image.tsx +12 -2
- package/tsconfig-build.tsbuildinfo +1 -1
package/dist/index.css
CHANGED
|
@@ -2613,6 +2613,7 @@ img.zoom-img {
|
|
|
2613
2613
|
}
|
|
2614
2614
|
/* Widget CSS */
|
|
2615
2615
|
.perseus-graph-padding {
|
|
2616
|
+
box-sizing: content-box;
|
|
2616
2617
|
padding: 25px 25px 0 0;
|
|
2617
2618
|
}
|
|
2618
2619
|
.categorizer-container {
|
|
@@ -2749,6 +2750,7 @@ body.mobile .categorizer-container td.category input[type="radio"] + span:active
|
|
|
2749
2750
|
margin: 0px 4px;
|
|
2750
2751
|
}
|
|
2751
2752
|
.perseus-widget-grapher {
|
|
2753
|
+
box-sizing: content-box;
|
|
2752
2754
|
padding: 25px 25px 0 0;
|
|
2753
2755
|
}
|
|
2754
2756
|
.perseus-widget-grapher > .graphie-container {
|
|
@@ -2793,7 +2795,8 @@ body.mobile .categorizer-container td.category input[type="radio"] + span:active
|
|
|
2793
2795
|
margin-left: -20px;
|
|
2794
2796
|
}
|
|
2795
2797
|
.perseus-image-widget {
|
|
2796
|
-
margin:
|
|
2798
|
+
margin-left: auto;
|
|
2799
|
+
margin-right: auto;
|
|
2797
2800
|
}
|
|
2798
2801
|
.perseus-image-widget .perseus-image-title {
|
|
2799
2802
|
text-align: center;
|
|
@@ -2802,7 +2805,6 @@ body.mobile .categorizer-container td.category input[type="radio"] + span:active
|
|
|
2802
2805
|
color: rgba(33, 36, 44, 0.7);
|
|
2803
2806
|
padding-left: 16px;
|
|
2804
2807
|
position: relative;
|
|
2805
|
-
top: -12px;
|
|
2806
2808
|
}
|
|
2807
2809
|
.perseus-image-widget .perseus-image-caption::before {
|
|
2808
2810
|
content: "";
|
|
@@ -2836,6 +2838,7 @@ body.mobile .categorizer-container td.category input[type="radio"] + span:active
|
|
|
2836
2838
|
margin-top: 5px;
|
|
2837
2839
|
}
|
|
2838
2840
|
.perseus-widget-interactive-graph {
|
|
2841
|
+
box-sizing: content-box;
|
|
2839
2842
|
padding: 25px 25px 0 0;
|
|
2840
2843
|
}
|
|
2841
2844
|
.perseus-widget-interactive-graph > .graphie-container {
|
package/dist/index.js
CHANGED
|
@@ -26771,7 +26771,10 @@ class ImageWidget extends React__namespace.Component {
|
|
|
26771
26771
|
})));
|
|
26772
26772
|
}
|
|
26773
26773
|
return /*#__PURE__*/React__namespace.createElement("figure", {
|
|
26774
|
-
className: "perseus-image-widget"
|
|
26774
|
+
className: "perseus-image-widget",
|
|
26775
|
+
style: {
|
|
26776
|
+
maxWidth: backgroundImage.width
|
|
26777
|
+
}
|
|
26775
26778
|
}, image, alt, titleAndCaption);
|
|
26776
26779
|
}
|
|
26777
26780
|
let title;
|
|
@@ -26798,7 +26801,10 @@ class ImageWidget extends React__namespace.Component {
|
|
|
26798
26801
|
}));
|
|
26799
26802
|
}
|
|
26800
26803
|
return /*#__PURE__*/React__namespace.createElement("figure", {
|
|
26801
|
-
className: "perseus-image-widget"
|
|
26804
|
+
className: "perseus-image-widget",
|
|
26805
|
+
style: {
|
|
26806
|
+
maxWidth: backgroundImage.width
|
|
26807
|
+
}
|
|
26802
26808
|
}, title, image, alt, caption);
|
|
26803
26809
|
}
|
|
26804
26810
|
static validate(userInput, rubric) {
|
|
@@ -44009,7 +44015,7 @@ const init = function (options) {
|
|
|
44009
44015
|
|
|
44010
44016
|
// This file is processed by a Rollup plugin (replace) to inject the production
|
|
44011
44017
|
const libName = "@khanacademy/perseus";
|
|
44012
|
-
const libVersion = "12.0
|
|
44018
|
+
const libVersion = "12.2.0";
|
|
44013
44019
|
perseusCore.addLibraryVersionToPerseusDebug(libName, libVersion);
|
|
44014
44020
|
|
|
44015
44021
|
const apiVersion = {
|
|
@@ -44031,6 +44037,7 @@ class ArticleRenderer extends React__namespace.Component {
|
|
|
44031
44037
|
constructor(props) {
|
|
44032
44038
|
super(props);
|
|
44033
44039
|
_defineProperty(this, "_currentFocus", void 0);
|
|
44040
|
+
_defineProperty(this, "sectionRenderers", []);
|
|
44034
44041
|
_defineProperty(this, "_handleFocusChange", (newFocusPath, oldFocusPath) => {
|
|
44035
44042
|
// TODO(charlie): DRY this up--some of this logic is repeated in
|
|
44036
44043
|
// ItemRenderer.
|
|
@@ -44055,17 +44062,17 @@ class ArticleRenderer extends React__namespace.Component {
|
|
|
44055
44062
|
// paths, so as to check whether the focused path represents an
|
|
44056
44063
|
// input.
|
|
44057
44064
|
let didFocusInput = false;
|
|
44065
|
+
let focusedInput;
|
|
44058
44066
|
if (this._currentFocus) {
|
|
44059
|
-
const [
|
|
44060
|
-
|
|
44061
|
-
// @ts-expect-error - TS2339 - Property 'getInputPaths' does not exist on type 'ReactInstance'.
|
|
44062
|
-
const inputPaths = this.refs[sectionRef].getInputPaths();
|
|
44067
|
+
const [sectionIndex, ...focusPath] = this._currentFocus;
|
|
44068
|
+
const inputPaths = this.sectionRenderers[sectionIndex].getInputPaths();
|
|
44063
44069
|
didFocusInput = inputPaths.some(inputPath => {
|
|
44064
44070
|
return Util.inputPathsEqual(inputPath, focusPath);
|
|
44065
44071
|
});
|
|
44072
|
+
focusedInput = this.sectionRenderers[sectionIndex].getDOMNodeForPath(focusPath);
|
|
44066
44073
|
}
|
|
44067
44074
|
if (this.props.apiOptions.onFocusChange != null) {
|
|
44068
|
-
this.props.apiOptions.onFocusChange(this._currentFocus, prevFocusPath, didFocusInput ? keypadElement === null || keypadElement === void 0 ? void 0 : keypadElement.getDOMNode() : null);
|
|
44075
|
+
this.props.apiOptions.onFocusChange(this._currentFocus, prevFocusPath, didFocusInput ? keypadElement === null || keypadElement === void 0 ? void 0 : keypadElement.getDOMNode() : null, didFocusInput ? focusedInput : null);
|
|
44069
44076
|
}
|
|
44070
44077
|
if (keypadElement && isMobile) {
|
|
44071
44078
|
if (didFocusInput) {
|
|
@@ -44097,10 +44104,8 @@ class ArticleRenderer extends React__namespace.Component {
|
|
|
44097
44104
|
});
|
|
44098
44105
|
_defineProperty(this, "blur", () => {
|
|
44099
44106
|
if (this._currentFocus) {
|
|
44100
|
-
const [
|
|
44101
|
-
|
|
44102
|
-
// @ts-expect-error - TS2339 - Property 'blurPath' does not exist on type 'ReactInstance'.
|
|
44103
|
-
this.refs[sectionRef].blurPath(inputPath);
|
|
44107
|
+
const [sectionIndex, ...inputPath] = this._currentFocus;
|
|
44108
|
+
this.sectionRenderers[sectionIndex].blurPath(inputPath);
|
|
44104
44109
|
}
|
|
44105
44110
|
});
|
|
44106
44111
|
_defineProperty(this, "_sections", () => {
|
|
@@ -44128,34 +44133,40 @@ class ArticleRenderer extends React__namespace.Component {
|
|
|
44128
44133
|
});
|
|
44129
44134
|
|
|
44130
44135
|
// TODO(alex): Add mobile api functions and pass them down here
|
|
44131
|
-
|
|
44132
|
-
|
|
44133
|
-
|
|
44134
|
-
|
|
44135
|
-
|
|
44136
|
-
key:
|
|
44136
|
+
// We're using the index as the key here because we don't have a unique
|
|
44137
|
+
// identifier for each section. This should be fine as we never remove
|
|
44138
|
+
// or reorder sections.
|
|
44139
|
+
const sections = this._sections().map((section, sectionIndex) => {
|
|
44140
|
+
return /*#__PURE__*/React__namespace.createElement("div", {
|
|
44141
|
+
key: sectionIndex,
|
|
44137
44142
|
className: "clearfix"
|
|
44138
44143
|
}, /*#__PURE__*/React__namespace.createElement(Renderer, _extends({}, section, {
|
|
44139
|
-
ref:
|
|
44140
|
-
|
|
44141
|
-
|
|
44144
|
+
ref: elem => {
|
|
44145
|
+
if (elem) {
|
|
44146
|
+
this.sectionRenderers[sectionIndex] = elem;
|
|
44147
|
+
}
|
|
44148
|
+
},
|
|
44149
|
+
key: sectionIndex,
|
|
44150
|
+
key_: sectionIndex,
|
|
44142
44151
|
keypadElement: this.props.keypadElement,
|
|
44143
44152
|
apiOptions: {
|
|
44144
44153
|
...apiOptions,
|
|
44145
44154
|
onFocusChange: (newFocusPath, oldFocusPath) => {
|
|
44146
|
-
// Prefix the paths with the relevant section,
|
|
44155
|
+
// Prefix the paths with the relevant section index,
|
|
44147
44156
|
// so as to allow us to distinguish between
|
|
44148
44157
|
// equivalently-named inputs across Renderers.
|
|
44149
|
-
this._handleFocusChange(newFocusPath && [
|
|
44158
|
+
this._handleFocusChange(newFocusPath && [sectionIndex].concat(newFocusPath), oldFocusPath && [sectionIndex].concat(oldFocusPath));
|
|
44150
44159
|
}
|
|
44151
44160
|
},
|
|
44152
44161
|
linterContext: PerseusLinter__namespace.pushContextStack(this.props.linterContext, "article"),
|
|
44153
44162
|
legacyPerseusLint: this.props.legacyPerseusLint
|
|
44154
|
-
})))
|
|
44163
|
+
})));
|
|
44155
44164
|
});
|
|
44156
44165
|
return /*#__PURE__*/React__namespace.createElement("div", {
|
|
44157
44166
|
className: classes
|
|
44158
|
-
},
|
|
44167
|
+
}, /*#__PURE__*/React__namespace.createElement(DependenciesContext.Provider, {
|
|
44168
|
+
value: this.props.dependencies
|
|
44169
|
+
}, sections));
|
|
44159
44170
|
}
|
|
44160
44171
|
}
|
|
44161
44172
|
_defineProperty(ArticleRenderer, "defaultProps", {
|