@khanacademy/perseus 16.0.0 → 17.0.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.
@@ -1,54 +0,0 @@
1
- import * as React from "react";
2
-
3
- import TexButtons from "../tex-buttons";
4
-
5
- type StoryArgs = Record<any, any>;
6
-
7
- type Story = {
8
- title: string;
9
- };
10
-
11
- export default {
12
- title: "Perseus/Components/Tex Buttons",
13
- } as Story;
14
-
15
- export const ButtonSetBasic = (args: StoryArgs): React.ReactElement => {
16
- return <TexButtons sets={["basic"]} onInsert={() => {}} />;
17
- };
18
-
19
- export const ButtonSetBasicDiv = (args: StoryArgs): React.ReactElement => {
20
- return <TexButtons sets={["basic+div"]} onInsert={() => {}} />;
21
- };
22
-
23
- export const ButtonSetTrig = (args: StoryArgs): React.ReactElement => {
24
- return <TexButtons sets={["trig"]} onInsert={() => {}} />;
25
- };
26
-
27
- export const ButtonSetPrealgebra = (args: StoryArgs): React.ReactElement => {
28
- return <TexButtons sets={["prealgebra"]} onInsert={() => {}} />;
29
- };
30
-
31
- export const ButtonSetLogarithms = (args: StoryArgs): React.ReactElement => {
32
- return <TexButtons sets={["logarithms"]} onInsert={() => {}} />;
33
- };
34
-
35
- export const ButtonSetBasicRelations = (
36
- args: StoryArgs,
37
- ): React.ReactElement => {
38
- return <TexButtons sets={["basic relations"]} onInsert={() => {}} />;
39
- };
40
-
41
- export const ButtonSetAdvancedRelations = (
42
- args: StoryArgs,
43
- ): React.ReactElement => {
44
- return <TexButtons sets={["advanced relations"]} onInsert={() => {}} />;
45
- };
46
-
47
- export const ButtonSetMultiple = (args: StoryArgs): React.ReactElement => {
48
- return (
49
- <TexButtons
50
- sets={["basic", "trig", "advanced relations"]}
51
- onInsert={() => {}}
52
- />
53
- );
54
- };
@@ -1,334 +0,0 @@
1
- /* eslint-disable @khanacademy/ts-no-error-suppressions */
2
- import * as i18n from "@khanacademy/wonder-blocks-i18n";
3
- import PropTypes from "prop-types";
4
- import * as React from "react";
5
- import _ from "underscore";
6
-
7
- import {getDependencies} from "../dependencies";
8
-
9
- import type {LegacyButtonSets} from "../perseus-types";
10
- import type {Keys} from "@khanacademy/math-input";
11
-
12
- const prettyBig = {fontSize: "150%"} as const;
13
- const slightlyBig = {fontSize: "120%"} as const;
14
- const symbStyle = {fontSize: "130%"} as const;
15
-
16
- type ButtonSet = (props: any) => [
17
- // inside of button
18
- React.ReactNode,
19
- // the key message it sends on click
20
- Keys,
21
- // label
22
- string,
23
- ];
24
-
25
- type ButtonSets = {
26
- readonly [key in LegacyButtonSets[number]]: ReadonlyArray<ButtonSet>;
27
- };
28
-
29
- // These are functions because we want to generate a new component for each use
30
- // on the page rather than reusing an instance (which will cause an error).
31
- // Also, it's useful for things which might look different depending on the
32
- // props.
33
-
34
- const basic: ReadonlyArray<ButtonSet> = [
35
- () => [
36
- <span key="plus" style={slightlyBig}>
37
- +
38
- </span>,
39
- "PLUS",
40
- i18n._("Plus"),
41
- ],
42
- () => [
43
- <span key="minus" style={prettyBig}>
44
- -
45
- </span>,
46
- "MINUS",
47
- i18n._("Minus"),
48
- ],
49
-
50
- // TODO(joel) - display as \cdot when appropriate
51
- (props: any) => {
52
- const {TeX} = getDependencies();
53
- if (props.convertDotToTimes) {
54
- return [
55
- <TeX key="times" style={prettyBig}>
56
- {i18n.doNotTranslate("\\times")}
57
- </TeX>,
58
- "TIMES",
59
- i18n._("Multiply"),
60
- ];
61
- }
62
- return [
63
- <TeX key="times" style={prettyBig}>
64
- {i18n.doNotTranslate("\\cdot")}
65
- </TeX>,
66
- "CDOT",
67
- i18n._("Multiply"),
68
- ];
69
- },
70
- () => {
71
- const {TeX} = getDependencies();
72
- return [
73
- <TeX key="frac" style={prettyBig}>
74
- {i18n.doNotTranslate("\\frac{x}{y}")}
75
- </TeX>,
76
- "FRAC",
77
- i18n._("Fraction, excluding the current expression"),
78
- ];
79
- },
80
- ];
81
-
82
- const buttonSets: ButtonSets = {
83
- basic,
84
-
85
- "basic+div": basic.concat([
86
- () => {
87
- const {TeX} = getDependencies();
88
- return [
89
- <TeX key="div">{i18n.doNotTranslate("\\div")}</TeX>,
90
- "DIVIDE",
91
- i18n._("Divide"),
92
- ];
93
- },
94
- ]),
95
-
96
- trig: [
97
- () => {
98
- const {TeX} = getDependencies();
99
- return [
100
- <TeX key="sin">{i18n.doNotTranslate("\\sin")}</TeX>,
101
- "SIN",
102
- i18n._("Sine"),
103
- ];
104
- },
105
- () => {
106
- const {TeX} = getDependencies();
107
- return [
108
- <TeX key="cos">{i18n.doNotTranslate("\\cos")}</TeX>,
109
- "COS",
110
- i18n._("Cosine"),
111
- ];
112
- },
113
- () => {
114
- const {TeX} = getDependencies();
115
- return [
116
- <TeX key="tan">{i18n.doNotTranslate("\\tan")}</TeX>,
117
- "TAN",
118
- i18n._("Tangent"),
119
- ];
120
- },
121
- () => {
122
- const {TeX} = getDependencies();
123
- return [
124
- <TeX key="theta" style={symbStyle}>
125
- {i18n.doNotTranslate("\\theta")}
126
- </TeX>,
127
- "THETA",
128
- i18n._("Theta"),
129
- ];
130
- },
131
- () => {
132
- const {TeX} = getDependencies();
133
- return [
134
- <span key="phi">
135
- {/*NOTE: KaTeX does not render "phi" for screen readers*/}
136
- <span className="perseus-sr-only">
137
- {i18n.doNotTranslate("phi")}
138
- </span>
139
- <TeX key="pi" style={symbStyle}>
140
- {i18n.doNotTranslate("\\phi")}
141
- </TeX>
142
- </span>,
143
- "PHI",
144
- i18n._("Phi"),
145
- ];
146
- },
147
- ],
148
-
149
- prealgebra: [
150
- () => {
151
- const {TeX} = getDependencies();
152
- return [
153
- <TeX key="sqrt">{i18n.doNotTranslate("\\sqrt{x}")}</TeX>,
154
- "SQRT",
155
- i18n._("Square root"),
156
- ];
157
- },
158
- // TODO(joel) - how does desmos do this?
159
- () => {
160
- const {TeX} = getDependencies();
161
- return [
162
- <TeX key="nthroot">{i18n.doNotTranslate("\\sqrt[3]{x}")}</TeX>,
163
- "NTHROOT3",
164
- i18n._("Cube root"),
165
- ];
166
- },
167
- () => {
168
- const {TeX} = getDependencies();
169
- return [
170
- <TeX key="pow" style={slightlyBig}>
171
- {i18n.doNotTranslate("a^b")}
172
- </TeX>,
173
- "POW",
174
- i18n._("Exponent"),
175
- ];
176
- },
177
- () => {
178
- const {TeX} = getDependencies();
179
- return [
180
- <TeX key="pi" style={slightlyBig}>
181
- {i18n.doNotTranslate("\\pi")}
182
- </TeX>,
183
- "PI",
184
- i18n._("Pi"),
185
- ];
186
- },
187
- ],
188
-
189
- logarithms: [
190
- () => {
191
- const {TeX} = getDependencies();
192
- return [
193
- <TeX key="log">{i18n.doNotTranslate("\\log")}</TeX>,
194
- "LOG",
195
- i18n._("Logarithm with base 10"),
196
- ];
197
- },
198
- () => {
199
- const {TeX} = getDependencies();
200
- return [
201
- <TeX key="ln">{i18n.doNotTranslate("\\ln")}</TeX>,
202
- "LN",
203
- i18n._("Natural logarithm"),
204
- ];
205
- },
206
- () => {
207
- const {TeX} = getDependencies();
208
- return [
209
- <TeX key="log_b">{i18n.doNotTranslate("\\log_b")}</TeX>,
210
- "LOG_B",
211
- i18n._("Logarithm with custom base"),
212
- ];
213
- },
214
- ],
215
-
216
- "basic relations": [
217
- () => {
218
- const {TeX} = getDependencies();
219
- return [<TeX key="eq">{"="}</TeX>, "EQUAL", i18n._("Equals sign")];
220
- },
221
- () => {
222
- const {TeX} = getDependencies();
223
- return [
224
- <TeX key="lt">{i18n.doNotTranslate("\\lt")}</TeX>,
225
- "LT",
226
- i18n._("Less than sign"),
227
- ];
228
- },
229
- () => {
230
- const {TeX} = getDependencies();
231
- return [
232
- <TeX key="gt">{i18n.doNotTranslate("\\gt")}</TeX>,
233
- "GT",
234
- i18n._("Greater than sign"),
235
- ];
236
- },
237
- ],
238
-
239
- "advanced relations": [
240
- () => {
241
- const {TeX} = getDependencies();
242
- return [
243
- <TeX key="neq">{i18n.doNotTranslate("\\neq")}</TeX>,
244
- "NEQ",
245
- i18n._("Not-equals sign"),
246
- ];
247
- },
248
- () => {
249
- const {TeX} = getDependencies();
250
- return [
251
- <TeX key="leq">{i18n.doNotTranslate("\\leq")}</TeX>,
252
- "LEQ",
253
- i18n._("Less than or equal to sign"),
254
- ];
255
- },
256
- () => {
257
- const {TeX} = getDependencies();
258
- return [
259
- <TeX key="geq">{i18n.doNotTranslate("\\geq")}</TeX>,
260
- "GEQ",
261
- i18n._("Greater than or equal to sign"),
262
- ];
263
- },
264
- ],
265
- };
266
-
267
- export type ButtonSetsType = ReadonlyArray<keyof typeof buttonSets>;
268
-
269
- type Props = {
270
- sets: ButtonSetsType;
271
- onInsert: (key: Keys) => void;
272
- className?: string;
273
- convertDotToTimes?: boolean;
274
- };
275
-
276
- const buttonSetsPropType = PropTypes.arrayOf(
277
- PropTypes.oneOf(_(buttonSets).keys()),
278
- );
279
-
280
- class TexButtons extends React.Component<Props> {
281
- static buttonSets: typeof buttonSets = buttonSets;
282
- static buttonSetsType: any = buttonSetsPropType;
283
-
284
- render(): React.ReactNode {
285
- // Always show buttonSets in the same order. Note: Technically it's ok
286
- // for _.keys() to return the keys in an arbitrary order, but in
287
- // practice, they will be ordered as listed above.
288
- const sortedButtonSets = _.sortBy(this.props.sets, (setName) =>
289
- _.keys(buttonSets).indexOf(setName),
290
- );
291
-
292
- const buttons = _(sortedButtonSets).map(
293
- (setName) => buttonSets[setName],
294
- );
295
-
296
- const buttonRows = _(buttons).map((row) =>
297
- row.map((symbGen) => {
298
- // create a (component, thing we should send to mathquill) pair
299
- const symbol = symbGen(this.props);
300
- return (
301
- <button
302
- onClick={() => this.props.onInsert(symbol[1])}
303
- className="tex-button"
304
- // @ts-expect-error - TS2533 - Object is possibly 'null' or 'undefined'. | TS2339 - Property 'key' does not exist on type 'boolean | ReactChild | ReactFragment | ReactPortal'.
305
- key={symbol[0].key}
306
- type="button"
307
- aria-label={symbol[2]}
308
- >
309
- {symbol[0]}
310
- </button>
311
- );
312
- }),
313
- );
314
-
315
- const buttonPopup = _(buttonRows).map((row, i) => {
316
- return (
317
- <div
318
- className="clearfix tex-button-row"
319
- key={this.props.sets[i]}
320
- >
321
- {row}
322
- </div>
323
- );
324
- });
325
-
326
- return (
327
- <div className={`${this.props.className || ""} preview-measure`}>
328
- {buttonPopup}
329
- </div>
330
- );
331
- }
332
- }
333
-
334
- export default TexButtons;