@khanacademy/perseus 7.0.2 → 7.1.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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Core Perseus API (includes renderers and widgets)",
4
4
  "author": "Khan Academy",
5
5
  "license": "MIT",
6
- "version": "7.0.2",
6
+ "version": "7.1.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -0,0 +1,17 @@
1
+ import React from "react";
2
+
3
+ import {passageArticle} from "../__testdata__/article-renderer.testdata";
4
+ import ArticleRenderer from "../article-renderer";
5
+
6
+ export default {
7
+ title: "Perseus/Renderers/Article Renderer",
8
+ argTypes: {
9
+ useNewStyles: {
10
+ control: "boolean",
11
+ },
12
+ },
13
+ };
14
+
15
+ export const PassageArticle = ({useNewStyles}): any => (
16
+ <ArticleRenderer json={passageArticle} useNewStyles={useNewStyles} />
17
+ );
@@ -0,0 +1,25 @@
1
+ export const passageArticle = {
2
+ content:
3
+ "###Group/Pair Activity \n\nThis passage is adapted from Ed Yong, “Turtles Use the Earth’s Magnetic Field as Global GPS.” ©2011 by Kalmbach Publishing Co.\n\n[[☃ passage 1]]\n\n**Question 9**\n\nThe passage most strongly suggests that Adelita used which of the following to navigate her 9,000-mile journey?\n\nA) The current of the North Atlantic gyre\n\nB) Cues from electromagnetic coils designed by Putman and Lohmann\n\nC) The inclination and intensity of Earth’s magnetic field\n\nD) A simulated “magnetic signature” configured by Lohmann\n\n10) Which choice provides the best evidence for the answer to the previous question?\n\nA) Lines 1–2 (“In 1996...way”)\n\nB) Lines 20–21 (“Using...surface”)\n\nC) Lines 36–37 (“In the wild...stars”)\n\nD) Lines 43–45 (“Neither...it is”)\n\n**Question 12** \n\nBased on the passage, which choice best describes the relationship between Putman’s and Lohmann’s research?\n\nA) Putman’s research contradicts Lohmann’s.\n\nB) Putman’s research builds on Lohmann’s.\n\nC) Lohmann’s research confirms Putman’s.\n\nD) Lohmann’s research corrects Putman’s.",
4
+ images: {},
5
+ widgets: {
6
+ "passage 1": {
7
+ type: "passage",
8
+ alignment: "default",
9
+ static: false,
10
+ graded: true,
11
+ options: {
12
+ static: false,
13
+ passageTitle: "",
14
+ passageText:
15
+ "In 1996, a loggerhead turtle called Adelita swam across 9,000 miles from Mexico to Japan, crossing the entire Pacific on her way. Wallace J. Nichols tracked this epic journey with a satellite tag. But Adelita herself had no such technology at her disposal. How did she steer a route across two oceans to find her destination?\n\nNathan Putman has the answer. By testing hatchling turtles in a special tank, he has found that they can use the Earth’s magnetic field as their own Global Positioning System (GPS). By sensing the field, they can work out both their latitude and longitude and head in the right direction.\n\nPutman works in the lab of Ken Lohmann, who has been studying the magnetic abilities of loggerheads for over 20 years. In his lab at the University of North Carolina, Lohmann places hatchlings in a large water tank surrounded by a large grid of electromagnetic coils. In 1991, he found that the babies started in the opposite direction if he used the coils to reverse the direction of the magnetic field around them. They could use the field as a compass to get their bearing.\n\nLater, Lohmann showed that they can also use the magnetic field to work out their position. For them, this is literally a matter of life or death. Hatchlings born off the sea coast of Florida spend their early lives in the North Atlantic gyre, a warm current that circles between North America and Africa. If they’re swept towards the cold waters outside the gyre, they die. Their magnetic sense keeps them safe.\n\nUsing his coil-surrounded tank, Lohmann could mimic the magnetic field at different parts of the Earth’s surface. If he simulated the field at the northern edge of the gyre, the hatchlings swam southwards. If he simulated the field at the gyre’s southern edge, the turtles swam west-northwest. These experiments showed that the turtles can use their magnetic sense to work out their latitude—their position on a north-south axis. Now, Putman has shown that they can also determine their longitude—their position on an east-west axis.\n\nHe tweaked his magnetic tanks to simulate the fields in two positions with the same latitude at opposite ends of the Atlantic. If the field simulated the west Atlantic near Puerto Rico, the turtles swam northeast. If the field matched that on the east Atlantic near the Cape Verde Islands, the turtles swam southwest. In the wild, both headings would keep them within the safe, warm embrace of the North Atlantic gyre.\nBefore now, we knew that several animal migrants, from loggerheads to reed warblers to sparrows, had some way of working out longitude, but no one knew how. By keeping the turtles in the same conditions, with only the magnetic fields around them changing, Putman clearly showed that they can use these fields to find their way. In the wild, they might well also use other landmarks like the position of the sea, sun and stars.\n\nPutman thinks that the turtles work out their position using two features of the Earth’s magnetic field that change over its surface. They can sense the field’s inclination, or the angle at which it dips towards the surface. At the poles, this angle is roughly 90 degrees and at the equator, it’s roughly zero degrees. They can also sense its intensity, which is strongest near the poles and weakest near the Equator. Different parts of the world have unique combinations of these two variables. Neither corresponds directly to either latitude or longitude, but together, they provide a “magnetic signature” that tells the turtle where it is.\n",
16
+ footnotes: "",
17
+ showLineNumbers: true,
18
+ },
19
+ version: {
20
+ major: 0,
21
+ minor: 0,
22
+ },
23
+ },
24
+ },
25
+ };
@@ -34,6 +34,9 @@ class ArticleRenderer extends React.Component<any, any> {
34
34
  ]).isRequired,
35
35
 
36
36
  // Whether to use the new Bibliotron styles for articles
37
+ /**
38
+ * @deprecated Does nothing
39
+ */
37
40
  useNewStyles: PropTypes.bool,
38
41
  linterContext: PerseusLinter.linterContextProps,
39
42
  legacyPerseusLint: PropTypes.arrayOf(PropTypes.string),
@@ -167,7 +170,6 @@ class ArticleRenderer extends React.Component<any, any> {
167
170
  const classes = classNames({
168
171
  "framework-perseus": true,
169
172
  "perseus-article": true,
170
- "bibliotron-article": this.props.useNewStyles,
171
173
  // NOTE(charlie): For exercises, this is applied outside of Perseus
172
174
  // (in webapp).
173
175
  [ApiClassNames.MOBILE]: apiOptions.isMobile,
@@ -3,49 +3,7 @@
3
3
  @import "./util.less";
4
4
 
5
5
  // Article Renderer
6
- // TODO(oliver): These are the old article styles. When we transition over
7
- // to the new styles we should remove these!
8
- .framework-perseus.perseus-article:not(.bibliotron-article) {
9
- .perseus-widget-container {
10
- &.widget-float-left {
11
- float: left;
12
- padding-right: 1em;
13
- max-width: 50%;
14
- width: 100%;
15
- }
16
-
17
- &.widget-float-right {
18
- float: right;
19
- padding-left: 1em;
20
- max-width: 50%;
21
- width: 100%;
22
- }
23
- }
24
-
25
- .perseus-renderer > .paragraph {
26
- margin-left: auto;
27
- margin-right: auto;
28
- max-width: 700px;
29
- }
30
-
31
- .paragraph.perseus-paragraph-full-width {
32
- margin-left: 0;
33
- margin-right: 0;
34
- max-width: none;
35
-
36
- > .paragraph {
37
- margin: 0;
38
- max-width: none;
39
- }
40
- }
41
- }
42
-
43
- // TODO(oliver): These are the new article styles. When we transition over
44
- // to the new styles we should remove the `.bibliotron-article` and delete
45
- // the above style rules.
46
- // NOTE(charlie): See below for the new, XOM Manatee beta typography styles,
47
- // which are applied to articles and exercises.
48
- .bibliotron-article.framework-perseus.perseus-article:not(.perseus-mobile) {
6
+ .framework-perseus.perseus-article:not(.perseus-mobile) {
49
7
  @textColor: #21242c;
50
8
  .body-text() {
51
9
  color: @textColor;
@@ -87,25 +45,28 @@
87
45
  .body-text;
88
46
  margin: 0 auto;
89
47
  max-width: @articleMaxWidth;
90
- }
91
- .perseus-renderer > .paragraph .paragraph {
92
- // These are actual paragraphs
93
- .body-text;
94
- margin-bottom: @paragraphSpacing;
95
- margin-top: 0;
48
+
49
+ .paragraph {
50
+ // These are actual paragraphs
51
+ .body-text;
52
+ margin-bottom: @paragraphSpacing;
53
+ margin-top: 0;
54
+ }
96
55
 
97
56
  // Inline math should have the same font-size as the surrounding text.
98
57
  // There is no wrapping element around .katex to indicate that it is
99
58
  // inline, so we rely on the "actual paragraph" check above
100
59
  // (a .paragraph that contains another .paragraph instead of a
101
60
  // .perseus-block-math).
102
- .katex, mjx-container {
61
+ .katex {
103
62
  font-size: 100%;
104
63
  }
64
+
65
+ ul:not(.perseus-widget-radio) {
66
+ .body-text;
67
+ }
105
68
  }
106
- .perseus-renderer > .paragraph ul:not(.perseus-widget-radio) {
107
- .body-text;
108
- }
69
+
109
70
  table {
110
71
  .body-text;
111
72
  margin-bottom: @paragraphSpacing;
@@ -293,15 +254,42 @@
293
254
  .choice-text(14px, 1.25);
294
255
  }
295
256
 
296
- // TODO(charlie): We're now applying the article typography styles to our
297
- // exercise content as well. We should remove the `.perseus-article` check and
298
- // merge these into `perseus-renderer.less`. However, we don't want to show them for
299
- // non-Bibliotron articles, so for now, we'll leave them here and enable them
300
- // explicitly for: (1) Bibliotron articles, and (2) all exercises.
301
- // TODO(charlie): When the XOM Manatee beta has concluded, we can remove the
302
- // namespacing and delete the above styles in full (assuming we ship the beta).
303
- .bibliotron-article.framework-perseus.perseus-article.perseus-mobile,
304
- .framework-perseus:not(.perseus-article).perseus-mobile {
257
+ .framework-perseus.perseus-mobile {
258
+ .perseus-article {
259
+ .perseus-widget-container {
260
+ &.widget-float-left {
261
+ float: left;
262
+ padding-right: 1em;
263
+ max-width: 50%;
264
+ width: 100%;
265
+ }
266
+
267
+ &.widget-float-right {
268
+ float: right;
269
+ padding-left: 1em;
270
+ max-width: 50%;
271
+ width: 100%;
272
+ }
273
+ }
274
+
275
+ .perseus-renderer > .paragraph {
276
+ margin-left: auto;
277
+ margin-right: auto;
278
+ max-width: 700px;
279
+ }
280
+
281
+ .paragraph.perseus-paragraph-full-width {
282
+ margin-left: 0;
283
+ margin-right: 0;
284
+ max-width: none;
285
+
286
+ > .paragraph {
287
+ margin: 0;
288
+ max-width: none;
289
+ }
290
+ }
291
+ }
292
+
305
293
  @baseUnit: 16px;
306
294
 
307
295
  // TODO(charlie): Pure defines XL as 1280px. However, Bibliotron and our new
@@ -1,6 +1,8 @@
1
- // this selector increases specificity to beat out other stylesheets while still
2
- // allowing for more than one passage widget on a page
3
- [id^="perseus-widget-passage-container"] {
1
+ // first one is to beat out specificity of article styles
2
+ .framework-perseus.perseus-article
3
+ .perseus-renderer
4
+ .perseus-widget-passage-container,
5
+ .perseus-widget-passage-container {
4
6
  // NOTE(mdr): This is similar to Wonder Blocks "BodySerif" typesetting, but
5
7
  // not quite: it's a bit smaller, for consistency with the sorta-small
6
8
  // type styles in rest of the Perseus.
@@ -10,7 +12,7 @@
10
12
  @font-size: 16px;
11
13
  @line-height: 20px;
12
14
 
13
- [id^="perseus-widget-passage"] {
15
+ .perseus-widget-passage {
14
16
  line-height: @line-height;
15
17
  margin: 22px;
16
18
  position: relative;
@@ -49,7 +51,7 @@
49
51
  // note(matthewc): If you need to change any of this,
50
52
  // check that line numbers line up correctly.
51
53
  // The margin should probably be 0 or the line height
52
- .passage-text div.paragraph {
54
+ > .passage-text div.paragraph {
53
55
  font-weight: 400;
54
56
  font-size: @font-size;
55
57
  line-height: @line-height;
@@ -17,7 +17,7 @@ exports[`passage-ref widget should render with invalid reference 1`] = `
17
17
  >
18
18
  <div>
19
19
  <div
20
- id="perseus-widget-passage-container-"
20
+ class="perseus-widget-passage-container"
21
21
  >
22
22
  <div
23
23
  class="perseus-widget-passage-instructions"
@@ -26,7 +26,7 @@ exports[`passage-ref widget should render with invalid reference 1`] = `
26
26
 
27
27
  </div>
28
28
  <div
29
- id="perseus-widget-passage-"
29
+ class="perseus-widget-passage"
30
30
  >
31
31
  <h3
32
32
  class="perseus-sr-only"
@@ -158,7 +158,7 @@ exports[`passage-ref widget should render with multi-line reference 1`] = `
158
158
  >
159
159
  <div>
160
160
  <div
161
- id="perseus-widget-passage-container-"
161
+ class="perseus-widget-passage-container"
162
162
  >
163
163
  <div
164
164
  class="perseus-widget-passage-instructions"
@@ -167,7 +167,7 @@ exports[`passage-ref widget should render with multi-line reference 1`] = `
167
167
 
168
168
  </div>
169
169
  <div
170
- id="perseus-widget-passage-"
170
+ class="perseus-widget-passage"
171
171
  >
172
172
  <h3
173
173
  class="perseus-sr-only"
@@ -304,7 +304,7 @@ exports[`passage-ref widget should render with single-line reference 1`] = `
304
304
  >
305
305
  <div>
306
306
  <div
307
- id="perseus-widget-passage-container-"
307
+ class="perseus-widget-passage-container"
308
308
  >
309
309
  <div
310
310
  class="perseus-widget-passage-instructions"
@@ -313,7 +313,7 @@ exports[`passage-ref widget should render with single-line reference 1`] = `
313
313
 
314
314
  </div>
315
315
  <div
316
- id="perseus-widget-passage-"
316
+ class="perseus-widget-passage"
317
317
  >
318
318
  <h3
319
319
  class="perseus-sr-only"
@@ -97,7 +97,7 @@ exports[`passage widget should snapshot multiple passages (mobile: false) 1`] =
97
97
  >
98
98
  <div>
99
99
  <div
100
- id="perseus-widget-passage-container-passage-1"
100
+ class="perseus-widget-passage-container"
101
101
  >
102
102
  <div
103
103
  class="perseus-widget-passage-instructions"
@@ -136,7 +136,7 @@ exports[`passage widget should snapshot multiple passages (mobile: false) 1`] =
136
136
  </div>
137
137
  </div>
138
138
  <div
139
- id="perseus-widget-passage-passage-1"
139
+ class="perseus-widget-passage"
140
140
  >
141
141
  <h3
142
142
  class="passage-title"
@@ -590,7 +590,7 @@ exports[`passage widget should snapshot multiple passages (mobile: false) 1`] =
590
590
  >
591
591
  <div>
592
592
  <div
593
- id="perseus-widget-passage-container-passage-2"
593
+ class="perseus-widget-passage-container"
594
594
  >
595
595
  <div
596
596
  class="perseus-widget-passage-instructions"
@@ -626,7 +626,7 @@ exports[`passage widget should snapshot multiple passages (mobile: false) 1`] =
626
626
  </div>
627
627
  </div>
628
628
  <div
629
- id="perseus-widget-passage-passage-2"
629
+ class="perseus-widget-passage"
630
630
  >
631
631
  <h3
632
632
  class="passage-title"
@@ -956,7 +956,7 @@ exports[`passage widget should snapshot multiple passages (mobile: true) 1`] = `
956
956
  >
957
957
  <div>
958
958
  <div
959
- id="perseus-widget-passage-container-passage-1"
959
+ class="perseus-widget-passage-container"
960
960
  >
961
961
  <div
962
962
  class="perseus-widget-passage-instructions"
@@ -995,7 +995,7 @@ exports[`passage widget should snapshot multiple passages (mobile: true) 1`] = `
995
995
  </div>
996
996
  </div>
997
997
  <div
998
- id="perseus-widget-passage-passage-1"
998
+ class="perseus-widget-passage"
999
999
  >
1000
1000
  <h3
1001
1001
  class="passage-title"
@@ -1449,7 +1449,7 @@ exports[`passage widget should snapshot multiple passages (mobile: true) 1`] = `
1449
1449
  >
1450
1450
  <div>
1451
1451
  <div
1452
- id="perseus-widget-passage-container-passage-2"
1452
+ class="perseus-widget-passage-container"
1453
1453
  >
1454
1454
  <div
1455
1455
  class="perseus-widget-passage-instructions"
@@ -1485,7 +1485,7 @@ exports[`passage widget should snapshot multiple passages (mobile: true) 1`] = `
1485
1485
  </div>
1486
1486
  </div>
1487
1487
  <div
1488
- id="perseus-widget-passage-passage-2"
1488
+ class="perseus-widget-passage"
1489
1489
  >
1490
1490
  <h3
1491
1491
  class="passage-title"
@@ -1778,7 +1778,7 @@ exports[`passage widget should snapshot simple passage (mobile: false) 1`] = `
1778
1778
  >
1779
1779
  <div>
1780
1780
  <div
1781
- id="perseus-widget-passage-container-"
1781
+ class="perseus-widget-passage-container"
1782
1782
  >
1783
1783
  <div
1784
1784
  class="perseus-widget-passage-instructions"
@@ -1787,7 +1787,7 @@ exports[`passage widget should snapshot simple passage (mobile: false) 1`] = `
1787
1787
 
1788
1788
  </div>
1789
1789
  <div
1790
- id="perseus-widget-passage-"
1790
+ class="perseus-widget-passage"
1791
1791
  >
1792
1792
  <h3
1793
1793
  class="perseus-sr-only"
@@ -1875,7 +1875,7 @@ exports[`passage widget should snapshot simple passage (mobile: true) 1`] = `
1875
1875
  >
1876
1876
  <div>
1877
1877
  <div
1878
- id="perseus-widget-passage-container-"
1878
+ class="perseus-widget-passage-container"
1879
1879
  >
1880
1880
  <div
1881
1881
  class="perseus-widget-passage-instructions"
@@ -1884,7 +1884,7 @@ exports[`passage widget should snapshot simple passage (mobile: true) 1`] = `
1884
1884
 
1885
1885
  </div>
1886
1886
  <div
1887
- id="perseus-widget-passage-"
1887
+ class="perseus-widget-passage"
1888
1888
  >
1889
1889
  <h3
1890
1890
  class="perseus-sr-only"
@@ -509,13 +509,12 @@ export class Passage extends React.Component<PassageProps, PassageState> {
509
509
  );
510
510
  // Check if the title has any non-empty text in it.
511
511
  const hasTitle = /\S/.test(this.props.passageTitle);
512
- const joinedTitle = joinString(this.props.passageTitle);
513
512
 
514
513
  return (
515
514
  <div>
516
- <div id={"perseus-widget-passage-container" + joinedTitle}>
515
+ <div className="perseus-widget-passage-container">
517
516
  {this._renderInstructions(parseState)}
518
- <div id={"perseus-widget-passage" + joinedTitle}>
517
+ <div className="perseus-widget-passage">
519
518
  {hasTitle && (
520
519
  <h3 className="passage-title">
521
520
  <Renderer
@@ -568,16 +567,6 @@ export class Passage extends React.Component<PassageProps, PassageState> {
568
567
  }
569
568
  }
570
569
 
571
- // That's All, Folks! => -thats-all-folks
572
- const joinString = (title: string): string =>
573
- "-" +
574
- title
575
- .toLowerCase()
576
- .replace(/[^\w\s]/gi, "")
577
- .trim()
578
- .split(/\s+/)
579
- .join("-");
580
-
581
570
  export default {
582
571
  name: "passage",
583
572
  displayName: "Passage (SAT only)",