@khanacademy/perseus 29.0.0 → 30.0.1

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.
@@ -7,18 +7,15 @@ import { PerseusI18nContext } from "./components/i18n-context";
7
7
  import { DependenciesContext } from "./dependencies";
8
8
  import Renderer from "./renderer";
9
9
  import type { PerseusRenderer } from "./perseus-types";
10
- import type { APIOptions, PerseusDependenciesV2 } from "./types";
10
+ import type { PerseusDependenciesV2, SharedRendererProps } from "./types";
11
11
  import type { KeypadAPI } from "@khanacademy/math-input";
12
12
  import type { KeypadContextRendererInterface } from "@khanacademy/perseus-core";
13
- import type { LinterContextProps } from "@khanacademy/perseus-linter";
14
- type Props = Partial<React.ContextType<typeof DependenciesContext>> & {
15
- apiOptions: APIOptions;
13
+ type Props = Partial<React.ContextType<typeof DependenciesContext>> & SharedRendererProps & {
16
14
  json: PerseusRenderer | ReadonlyArray<PerseusRenderer>;
17
15
  /**
18
16
  * @deprecated Does nothing
19
17
  */
20
18
  useNewStyles: boolean;
21
- linterContext: LinterContextProps;
22
19
  legacyPerseusLint?: ReadonlyArray<string>;
23
20
  keypadElement?: KeypadAPI | null | undefined;
24
21
  dependencies: PerseusDependenciesV2;
@@ -14,6 +14,9 @@ type Props = {
14
14
  blockHighlight?: boolean;
15
15
  severity?: Severity;
16
16
  };
17
+ type State = {
18
+ tooltipAbove: boolean;
19
+ };
17
20
  /**
18
21
  * This component renders "lint" nodes in a markdown parse tree. Lint nodes
19
22
  * are inserted into the tree by the Perseus linter (see
@@ -36,8 +39,12 @@ type Props = {
36
39
  * that has a right margin (like anything blockquoted) the circle will appear
37
40
  * to the left of where it belongs. And if there is more
38
41
  **/
39
- declare class Lint extends React.Component<Props> {
42
+ declare class Lint extends React.Component<Props, State> {
40
43
  _positionTimeout: number | undefined;
44
+ state: State;
45
+ componentDidMount(): void;
46
+ componentWillUnmount(): void;
47
+ getPosition: () => void;
41
48
  renderLink: (arg1: any) => React.ReactElement;
42
49
  render(): React.ReactNode;
43
50
  }
package/dist/es/index.js CHANGED
@@ -15,7 +15,7 @@ import ReactDOM__default from 'react-dom';
15
15
  import _, { debounce as debounce$1 } from 'underscore';
16
16
  import Clickable from '@khanacademy/wonder-blocks-clickable';
17
17
  import { Popover, PopoverContentCore, PopoverContent } from '@khanacademy/wonder-blocks-popover';
18
- import { color, spacing, font } from '@khanacademy/wonder-blocks-tokens';
18
+ import { color, spacing } from '@khanacademy/wonder-blocks-tokens';
19
19
  import $ from 'jquery';
20
20
  import { v4 } from 'uuid';
21
21
  import PropTypes from 'prop-types';
@@ -247,7 +247,10 @@ const mockStrings = {
247
247
  somethingWrong: "Something went wrong.",
248
248
  videoWrapper: "Khan Academy video wrapper",
249
249
  mathInputTitle: "mathematics keyboard",
250
- mathInputDescription: "Use keyboard/mouse to interact with math-based input fields"
250
+ mathInputDescription: "Use keyboard/mouse to interact with math-based input fields",
251
+ sin: "sin",
252
+ cos: "cos",
253
+ tan: "tan"
251
254
  };
252
255
 
253
256
  /**
@@ -328,7 +331,7 @@ class InnerMathInput extends React.Component {
328
331
  const {
329
332
  locale
330
333
  } = this.context;
331
- const customKeyTranslator = _extends({}, getKeyTranslator(locale), {
334
+ const customKeyTranslator = _extends({}, getKeyTranslator(locale, this.context.strings), {
332
335
  // If there's something in the input that can become part of a
333
336
  // fraction, typing "/" puts it in the numerator. If not, typing
334
337
  // "/" does nothing. In that case, enter a \frac.
@@ -447,7 +450,7 @@ class InnerMathInput extends React.Component {
447
450
  const {
448
451
  locale
449
452
  } = this.context;
450
- const translator = getKeyTranslator(locale)[key];
453
+ const translator = getKeyTranslator(locale, this.context.strings)[key];
451
454
  const mathField = this.mathField();
452
455
  if (mathField) {
453
456
  if (translator) {
@@ -18171,9 +18174,27 @@ class Lint extends React.Component {
18171
18174
  constructor(...args) {
18172
18175
  super(...args);
18173
18176
  this._positionTimeout = void 0;
18177
+ this.state = {
18178
+ tooltipAbove: true
18179
+ };
18180
+ // We can't call setState in componentDidMount without risking a render
18181
+ // thrash, and we can't call getBoundingClientRect in render, so we
18182
+ // borrow a timeout approach from learnstorm-dashboard.jsx and set our
18183
+ // state once the component has mounted and we can get what we need.
18184
+ this.getPosition = () => {
18185
+ // @ts-expect-error - TS2531 - Object is possibly 'null'. | TS2339 - Property 'getBoundingClientRect' does not exist on type 'Element | Text'.
18186
+ const rect = ReactDOM__default.findDOMNode(this).getBoundingClientRect();
18187
+ // TODO(scottgrant): This is a magic number! We don't know the size
18188
+ // of the tooltip at this point, so we're arbitrarily choosing a
18189
+ // point at which to flip the tooltip's position.
18190
+ this.setState({
18191
+ tooltipAbove: rect.top > 100
18192
+ });
18193
+ };
18174
18194
  // Render the <a> element that holds the indicator icon and the tooltip
18175
18195
  // We pass different styles for the inline and block cases
18176
18196
  this.renderLink = style => {
18197
+ const tooltipAbove = this.state.tooltipAbove;
18177
18198
  let severityStyle;
18178
18199
  let warningText;
18179
18200
  let warningTextStyle;
@@ -18190,23 +18211,34 @@ class Lint extends React.Component {
18190
18211
  warningText = "Recommendation";
18191
18212
  warningTextStyle = styles$B.warning;
18192
18213
  }
18193
- return /*#__PURE__*/React.createElement(Tooltip$1, {
18194
- backgroundColor: "offBlack",
18195
- content: /*#__PURE__*/React.createElement(React.Fragment, null, this.props.message.split("\n\n").map((m, i) => /*#__PURE__*/React.createElement("p", {
18196
- key: i,
18197
- className: css(styles$B.tooltipParagraph)
18198
- }, /*#__PURE__*/React.createElement("span", {
18199
- className: css(warningTextStyle)
18200
- }, warningText, ":", " "), m)))
18201
- }, /*#__PURE__*/React.createElement("a", {
18214
+ return /*#__PURE__*/React.createElement("a", {
18202
18215
  href: `https://khanacademy.org/r/linter-rules#${this.props.ruleName}`,
18203
18216
  target: "lint-help-window",
18204
18217
  className: css(style)
18205
18218
  }, /*#__PURE__*/React.createElement("span", {
18206
18219
  className: css(styles$B.indicator, severityStyle)
18207
- }, this.props.severity === 1 && /*#__PURE__*/React.createElement(InlineIcon, exclamationIcon))));
18220
+ }, this.props.severity === 1 && /*#__PURE__*/React.createElement(InlineIcon, exclamationIcon)), /*#__PURE__*/React.createElement("div", {
18221
+ className: css(styles$B.tooltip, tooltipAbove && styles$B.tooltipAbove)
18222
+ }, this.props.message.split("\n\n").map((m, i) => /*#__PURE__*/React.createElement("p", {
18223
+ key: i,
18224
+ className: css(styles$B.tooltipParagraph)
18225
+ }, /*#__PURE__*/React.createElement("span", {
18226
+ className: css(warningTextStyle)
18227
+ }, warningText, ":", " "), m)), /*#__PURE__*/React.createElement("div", {
18228
+ className: css(styles$B.tail, tooltipAbove && styles$B.tailAbove)
18229
+ })));
18208
18230
  };
18209
18231
  }
18232
+ componentDidMount() {
18233
+ // TODO(somewhatabstract): Use WB timing
18234
+ // eslint-disable-next-line no-restricted-syntax
18235
+ this._positionTimeout = window.setTimeout(this.getPosition);
18236
+ }
18237
+ componentWillUnmount() {
18238
+ // TODO(somewhatabstract): Use WB timing
18239
+ // eslint-disable-next-line no-restricted-syntax
18240
+ window.clearTimeout(this._positionTimeout);
18241
+ }
18210
18242
  // The main render method surrounds linty content with a block or
18211
18243
  // inline container and the link element that displays the indicator
18212
18244
  // and holds the tooltip.
@@ -18407,11 +18439,54 @@ const styles$B = StyleSheet.create({
18407
18439
  indicatorGuideline: {
18408
18440
  backgroundColor: "#ffbe26"
18409
18441
  },
18442
+ // These are the styles for the tooltip
18443
+ tooltip: {
18444
+ // Absolute positioning relative to the lint indicator circle.
18445
+ position: "absolute",
18446
+ right: -12,
18447
+ // The tooltip is hidden by default; only displayed on hover
18448
+ display: "none",
18449
+ // When it is displayed, it goes on top!
18450
+ zIndex: 1000,
18451
+ // These styles control what the tooltip looks like
18452
+ color: white$1,
18453
+ backgroundColor: gray17,
18454
+ opacity: 0.9,
18455
+ fontFamily: baseFontFamily$1,
18456
+ fontSize: "12px",
18457
+ lineHeight: "15px",
18458
+ width: "320px",
18459
+ borderRadius: "4px"
18460
+ },
18461
+ // If we're going to render the tooltip above the warning circle, we use
18462
+ // the previous rules in tooltip, but change the position slightly.
18463
+ tooltipAbove: {
18464
+ bottom: 32
18465
+ },
18466
+ // We give the tooltip a little triangular "tail" that points down at
18467
+ // the lint indicator circle. This is inside the tooltip and positioned
18468
+ // relative to it. It also shares the opacity of the tooltip. We're using
18469
+ // the standard CSS trick for drawing triangles with a thick border.
18470
+ tail: {
18471
+ position: "absolute",
18472
+ top: -12,
18473
+ right: 16,
18474
+ width: 0,
18475
+ height: 0,
18476
+ // This is the CSS triangle trick
18477
+ borderLeft: "8px solid transparent",
18478
+ borderRight: "8px solid transparent",
18479
+ borderBottom: "12px solid " + gray17
18480
+ },
18481
+ tailAbove: {
18482
+ bottom: -12,
18483
+ borderBottom: "none",
18484
+ borderTop: "12px solid " + gray17,
18485
+ top: "auto"
18486
+ },
18410
18487
  // Each warning in the tooltip is its own <p>. They are 12 pixels from
18411
18488
  // the edges of the tooltip and 12 pixels from each other.
18412
18489
  tooltipParagraph: {
18413
- fontFamily: font.family.sans,
18414
- color: color.white,
18415
18490
  margin: 12
18416
18491
  },
18417
18492
  // The text "Warning" inside the tooltip is highlighted like this
@@ -44201,7 +44276,7 @@ const init = function init(options) {
44201
44276
 
44202
44277
  // This file is processed by a Rollup plugin (replace) to inject the production
44203
44278
  const libName = "@khanacademy/perseus";
44204
- const libVersion = "29.0.0";
44279
+ const libVersion = "30.0.1";
44205
44280
  addLibraryVersionToPerseusDebug(libName, libVersion);
44206
44281
 
44207
44282
  const apiVersion = {