@khanacademy/perseus 1.1.2 → 1.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 +12 -0
- package/dist/es/index.css +1 -2
- package/dist/es/index.js +1144 -1262
- package/dist/es/index.js.map +1 -1
- package/dist/index.css +1 -2
- package/dist/index.js +1147 -1264
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/__tests__/__snapshots__/renderer_test.jsx.snap +21 -3
- package/src/components/highlighting/ui/highlight-tooltip.jsx +29 -23
- package/src/components/highlighting/ui/selection-tracker.jsx +17 -28
- package/src/styles/articles.less +0 -2
- package/src/styles/perseus-renderer.less +1 -1
- package/src/widgets/__tests__/__snapshots__/dropdown_test.jsx.snap +16 -2
- package/src/components/new-tooltip/README.md +0 -3
- package/src/components/new-tooltip/__stories__/new-tooltip.stories.jsx +0 -665
- package/src/components/new-tooltip/__tests__/style-constants_test.js +0 -8
- package/src/components/new-tooltip/new-tooltip.jsx +0 -155
- package/src/components/new-tooltip/style-constants.js +0 -13
- package/src/components/new-tooltip/types.js +0 -183
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": "1.
|
|
6
|
+
"version": "1.2.0",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
@@ -35,16 +35,16 @@
|
|
|
35
35
|
"@khanacademy/wonder-blocks-color": "^1.1.20",
|
|
36
36
|
"@khanacademy/wonder-blocks-core": "^4.3.0",
|
|
37
37
|
"@khanacademy/wonder-blocks-data": "^7.0.0",
|
|
38
|
-
"@khanacademy/wonder-blocks-dropdown": "^2.
|
|
38
|
+
"@khanacademy/wonder-blocks-dropdown": "^2.10.1",
|
|
39
39
|
"@khanacademy/wonder-blocks-form": "^2.4.5",
|
|
40
40
|
"@khanacademy/wonder-blocks-i18n": "^1.2.3",
|
|
41
41
|
"@khanacademy/wonder-blocks-layout": "^1.4.9",
|
|
42
42
|
"@khanacademy/wonder-blocks-link": "^3.8.5",
|
|
43
43
|
"@khanacademy/wonder-blocks-modal": "^2.3.1",
|
|
44
|
-
"@khanacademy/wonder-blocks-popover": "^1.1.
|
|
44
|
+
"@khanacademy/wonder-blocks-popover": "^1.1.24",
|
|
45
45
|
"@khanacademy/wonder-blocks-progress-spinner": "^1.1.31",
|
|
46
46
|
"@khanacademy/wonder-blocks-spacing": "^3.0.5",
|
|
47
|
-
"@khanacademy/wonder-blocks-tooltip": "^1.
|
|
47
|
+
"@khanacademy/wonder-blocks-tooltip": "^1.4.0",
|
|
48
48
|
"@khanacademy/wonder-blocks-typography": "^1.1.31",
|
|
49
49
|
"@khanacademy/wonder-stuff-core": "^0.1.2",
|
|
50
50
|
"aphrodite": "^1.2.5",
|
|
@@ -68,16 +68,16 @@
|
|
|
68
68
|
"@khanacademy/wonder-blocks-color": "^1.1.20",
|
|
69
69
|
"@khanacademy/wonder-blocks-core": "^4.3.0",
|
|
70
70
|
"@khanacademy/wonder-blocks-data": "^7.0.0",
|
|
71
|
-
"@khanacademy/wonder-blocks-dropdown": "^2.
|
|
71
|
+
"@khanacademy/wonder-blocks-dropdown": "^2.10.1",
|
|
72
72
|
"@khanacademy/wonder-blocks-form": "^2.4.5",
|
|
73
73
|
"@khanacademy/wonder-blocks-i18n": "^1.2.3",
|
|
74
74
|
"@khanacademy/wonder-blocks-layout": "^1.4.9",
|
|
75
75
|
"@khanacademy/wonder-blocks-link": "^3.8.5",
|
|
76
76
|
"@khanacademy/wonder-blocks-modal": "^2.3.1",
|
|
77
|
-
"@khanacademy/wonder-blocks-popover": "^1.1.
|
|
77
|
+
"@khanacademy/wonder-blocks-popover": "^1.1.24",
|
|
78
78
|
"@khanacademy/wonder-blocks-progress-spinner": "^1.1.31",
|
|
79
79
|
"@khanacademy/wonder-blocks-spacing": "^3.0.5",
|
|
80
|
-
"@khanacademy/wonder-blocks-tooltip": "^1.
|
|
80
|
+
"@khanacademy/wonder-blocks-tooltip": "^1.4.0",
|
|
81
81
|
"@khanacademy/wonder-blocks-typography": "^1.1.31",
|
|
82
82
|
"@khanacademy/wonder-stuff-core": "^0.1.2",
|
|
83
83
|
"aphrodite": "^1.2.5",
|
|
@@ -385,11 +385,17 @@ exports[`renderer snapshots correct answer: correct answer 1`] = `
|
|
|
385
385
|
<div
|
|
386
386
|
class="default_xu2jcg-o_O-menuWrapper_wvrnr4"
|
|
387
387
|
>
|
|
388
|
+
<span
|
|
389
|
+
aria-atomic="true"
|
|
390
|
+
aria-live="polite"
|
|
391
|
+
aria-relevant="additions text"
|
|
392
|
+
class="srOnly_19bpjuy"
|
|
393
|
+
data-test-id="dropdown-live-region"
|
|
394
|
+
/>
|
|
388
395
|
<button
|
|
389
396
|
aria-expanded="false"
|
|
390
397
|
aria-haspopup="listbox"
|
|
391
398
|
class="button_vr44p2-o_O-shared_u51dsh-o_O-default_kjzwx1-o_O-focus_1qpi544"
|
|
392
|
-
tabindex="0"
|
|
393
399
|
type="button"
|
|
394
400
|
>
|
|
395
401
|
<span
|
|
@@ -456,11 +462,17 @@ exports[`renderer snapshots incorrect answer: incorrect answer 1`] = `
|
|
|
456
462
|
<div
|
|
457
463
|
class="default_xu2jcg-o_O-menuWrapper_wvrnr4"
|
|
458
464
|
>
|
|
465
|
+
<span
|
|
466
|
+
aria-atomic="true"
|
|
467
|
+
aria-live="polite"
|
|
468
|
+
aria-relevant="additions text"
|
|
469
|
+
class="srOnly_19bpjuy"
|
|
470
|
+
data-test-id="dropdown-live-region"
|
|
471
|
+
/>
|
|
459
472
|
<button
|
|
460
473
|
aria-expanded="false"
|
|
461
474
|
aria-haspopup="listbox"
|
|
462
475
|
class="button_vr44p2-o_O-shared_u51dsh-o_O-default_kjzwx1-o_O-focus_1qpi544"
|
|
463
|
-
tabindex="0"
|
|
464
476
|
type="button"
|
|
465
477
|
>
|
|
466
478
|
<span
|
|
@@ -527,11 +539,17 @@ exports[`renderer snapshots initial render: initial render 1`] = `
|
|
|
527
539
|
<div
|
|
528
540
|
class="default_xu2jcg-o_O-menuWrapper_wvrnr4"
|
|
529
541
|
>
|
|
542
|
+
<span
|
|
543
|
+
aria-atomic="true"
|
|
544
|
+
aria-live="polite"
|
|
545
|
+
aria-relevant="additions text"
|
|
546
|
+
class="srOnly_19bpjuy"
|
|
547
|
+
data-test-id="dropdown-live-region"
|
|
548
|
+
/>
|
|
530
549
|
<button
|
|
531
550
|
aria-expanded="false"
|
|
532
551
|
aria-haspopup="listbox"
|
|
533
552
|
class="button_vr44p2-o_O-shared_u51dsh-o_O-default_kjzwx1"
|
|
534
|
-
tabindex="0"
|
|
535
553
|
type="button"
|
|
536
554
|
>
|
|
537
555
|
<span
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
* still have to notify the tooltip to remeasure itself when the highlight
|
|
14
14
|
* focus _changes_.
|
|
15
15
|
*/
|
|
16
|
+
import Spacing from "@khanacademy/wonder-blocks-spacing";
|
|
17
|
+
import Tooltip from "@khanacademy/wonder-blocks-tooltip";
|
|
16
18
|
import {StyleSheet, css} from "aphrodite";
|
|
17
19
|
import * as React from "react";
|
|
18
20
|
|
|
19
21
|
import {Log} from "../../../logging/log.js";
|
|
20
|
-
import {colors} from "../../../styles/global-styles.js";
|
|
21
|
-
import NewTooltip from "../../new-tooltip/new-tooltip.jsx";
|
|
22
22
|
|
|
23
23
|
import {getRelativeRect} from "./util.js";
|
|
24
24
|
|
|
@@ -36,8 +36,6 @@ type HighlightTooltipProps = {|
|
|
|
36
36
|
|};
|
|
37
37
|
|
|
38
38
|
class HighlightTooltip extends React.PureComponent<HighlightTooltipProps> {
|
|
39
|
-
_tooltip: ?React.ElementRef<typeof NewTooltip>;
|
|
40
|
-
|
|
41
39
|
_getFocusRect(): ?Rect {
|
|
42
40
|
const {focusNode, focusOffset, offsetParent} = this.props;
|
|
43
41
|
|
|
@@ -94,31 +92,36 @@ class HighlightTooltip extends React.PureComponent<HighlightTooltipProps> {
|
|
|
94
92
|
return null;
|
|
95
93
|
}
|
|
96
94
|
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
// using div instead of TooltipContent because
|
|
96
|
+
// TooltipContent wouldn't let me overwrite
|
|
97
|
+
// user-select and onClick
|
|
98
|
+
const content: $FlowFixMe = (
|
|
99
|
+
<div
|
|
100
|
+
className={css(styles.tooltipLabel)}
|
|
101
|
+
onClick={this.props.onClick}
|
|
102
|
+
>
|
|
103
|
+
{this.props.label}
|
|
104
|
+
</div>
|
|
99
105
|
);
|
|
100
106
|
|
|
107
|
+
const style = {
|
|
108
|
+
position: "absolute",
|
|
109
|
+
left: focusRect.left,
|
|
110
|
+
// offset the spacing WB provides around tooltips
|
|
111
|
+
top: `calc(${Math.round(focusRect.top)}px + 0.95em)`,
|
|
112
|
+
height: 0,
|
|
113
|
+
};
|
|
114
|
+
|
|
101
115
|
return (
|
|
102
|
-
<
|
|
103
|
-
|
|
104
|
-
color={colors.kaBlue}
|
|
105
|
-
inverted={true}
|
|
106
|
-
onClick={this.props.onClick}
|
|
116
|
+
<div
|
|
117
|
+
style={style}
|
|
107
118
|
onMouseEnter={this.props.onMouseEnter}
|
|
108
119
|
onMouseLeave={this.props.onMouseLeave}
|
|
109
|
-
toggleOnHover={false}
|
|
110
|
-
showOnMount={true}
|
|
111
|
-
ref={(e) => (this._tooltip = e)}
|
|
112
120
|
>
|
|
113
|
-
<
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
top: focusRect.top,
|
|
118
|
-
height: focusRect.height,
|
|
119
|
-
}}
|
|
120
|
-
/>
|
|
121
|
-
</NewTooltip>
|
|
121
|
+
<Tooltip content={content} opened={true}>
|
|
122
|
+
<div />
|
|
123
|
+
</Tooltip>
|
|
124
|
+
</div>
|
|
122
125
|
);
|
|
123
126
|
}
|
|
124
127
|
}
|
|
@@ -131,6 +134,9 @@ const styles = StyleSheet.create({
|
|
|
131
134
|
// we lose our reference to the _actual_ text they want to highlight,
|
|
132
135
|
// and the "Add highlight" action fails.
|
|
133
136
|
userSelect: "none",
|
|
137
|
+
fontFamily: `"Lato", sans-serif`,
|
|
138
|
+
padding: `10px ${Spacing.medium_16}px`,
|
|
139
|
+
cursor: "pointer",
|
|
134
140
|
},
|
|
135
141
|
});
|
|
136
142
|
|
|
@@ -24,7 +24,7 @@ export type TrackedSelection = {|
|
|
|
24
24
|
proposedHighlight: DOMHighlight,
|
|
25
25
|
|};
|
|
26
26
|
|
|
27
|
-
type SelectionTrackerProps = {
|
|
27
|
+
type SelectionTrackerProps = {|
|
|
28
28
|
// A function that builds a DOMHighlight from the given DOMRange, if
|
|
29
29
|
// possible. If it would not currently be valid to add a highlight over the
|
|
30
30
|
// given DOMRange, returns null.
|
|
@@ -38,17 +38,15 @@ type SelectionTrackerProps = {
|
|
|
38
38
|
) => React.Element<any>,
|
|
39
39
|
// If false, will not track selections.
|
|
40
40
|
enabled: boolean,
|
|
41
|
-
|
|
42
|
-
};
|
|
41
|
+
|};
|
|
43
42
|
|
|
44
|
-
type SelectionTrackerState = {
|
|
43
|
+
type SelectionTrackerState = {|
|
|
45
44
|
// The current state of the mouse button. We distinguish between down,
|
|
46
45
|
// down and the selection has changed since going down, and up.
|
|
47
46
|
mouseState: "down" | "down-and-selecting" | "up",
|
|
48
47
|
// The current TrackedSelection, if any.
|
|
49
48
|
trackedSelection: ?TrackedSelection,
|
|
50
|
-
|
|
51
|
-
};
|
|
49
|
+
|};
|
|
52
50
|
|
|
53
51
|
class SelectionTracker extends React.PureComponent<
|
|
54
52
|
SelectionTrackerProps,
|
|
@@ -63,15 +61,15 @@ class SelectionTracker extends React.PureComponent<
|
|
|
63
61
|
this._updateListeners(false, this.props.enabled);
|
|
64
62
|
}
|
|
65
63
|
|
|
66
|
-
|
|
67
|
-
if (this.props.buildHighlight !==
|
|
64
|
+
componentDidUpdate(prevProps: SelectionTrackerProps) {
|
|
65
|
+
if (this.props.buildHighlight !== prevProps.buildHighlight) {
|
|
68
66
|
// The highlight-building function changed, so the
|
|
69
67
|
// proposedHighlight we built with it might be different, or no
|
|
70
68
|
// longer be valid. Update accordingly.
|
|
71
|
-
this._updateTrackedSelection(
|
|
69
|
+
this._updateTrackedSelection();
|
|
72
70
|
}
|
|
73
71
|
|
|
74
|
-
this._updateListeners(
|
|
72
|
+
this._updateListeners(prevProps.enabled, this.props.enabled);
|
|
75
73
|
}
|
|
76
74
|
|
|
77
75
|
componentWillUnmount() {
|
|
@@ -133,37 +131,28 @@ class SelectionTracker extends React.PureComponent<
|
|
|
133
131
|
}
|
|
134
132
|
|
|
135
133
|
/**
|
|
136
|
-
* Compute the
|
|
134
|
+
* Compute and update the TrackedSelection to reflect the document state.
|
|
137
135
|
*/
|
|
138
|
-
|
|
139
|
-
buildHighlight: (domRange: DOMRange) => ?DOMHighlight,
|
|
140
|
-
): ?TrackedSelection {
|
|
136
|
+
_updateTrackedSelection(): void {
|
|
141
137
|
const focusAndRange = this._computeFocusAndRange();
|
|
142
138
|
if (!focusAndRange) {
|
|
143
|
-
|
|
139
|
+
this.setState({trackedSelection: null});
|
|
140
|
+
return;
|
|
144
141
|
}
|
|
145
142
|
|
|
146
143
|
const {focusNode, focusOffset, range} = focusAndRange;
|
|
147
|
-
const proposedHighlight = buildHighlight(range);
|
|
144
|
+
const proposedHighlight = this.props.buildHighlight(range);
|
|
148
145
|
if (!proposedHighlight) {
|
|
149
|
-
|
|
146
|
+
this.setState({trackedSelection: null});
|
|
147
|
+
return;
|
|
150
148
|
}
|
|
151
149
|
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Update the TrackedSelection to reflect the document state.
|
|
157
|
-
*/
|
|
158
|
-
_updateTrackedSelection(
|
|
159
|
-
buildHighlight: (domRange: DOMRange) => ?DOMHighlight,
|
|
160
|
-
) {
|
|
161
|
-
const trackedSelection = this._computeTrackedSelection(buildHighlight);
|
|
150
|
+
const trackedSelection = {focusNode, focusOffset, proposedHighlight};
|
|
162
151
|
this.setState({trackedSelection});
|
|
163
152
|
}
|
|
164
153
|
|
|
165
154
|
_handleSelectionChange: () => void = () => {
|
|
166
|
-
this._updateTrackedSelection(
|
|
155
|
+
this._updateTrackedSelection();
|
|
167
156
|
|
|
168
157
|
if (this.state.mouseState === "down") {
|
|
169
158
|
this.setState({
|
package/src/styles/articles.less
CHANGED
|
@@ -23,11 +23,19 @@ exports[`Dropdown widget should snapshot when opened: dropdown open 1`] = `
|
|
|
23
23
|
<div
|
|
24
24
|
class="default_xu2jcg-o_O-menuWrapper_wvrnr4"
|
|
25
25
|
>
|
|
26
|
+
<span
|
|
27
|
+
aria-atomic="true"
|
|
28
|
+
aria-live="polite"
|
|
29
|
+
aria-relevant="additions text"
|
|
30
|
+
class="srOnly_19bpjuy"
|
|
31
|
+
data-test-id="dropdown-live-region"
|
|
32
|
+
>
|
|
33
|
+
3 items
|
|
34
|
+
</span>
|
|
26
35
|
<button
|
|
27
36
|
aria-expanded="true"
|
|
28
37
|
aria-haspopup="listbox"
|
|
29
38
|
class="button_vr44p2-o_O-shared_u51dsh-o_O-default_kjzwx1-o_O-focus_1qpi544"
|
|
30
|
-
tabindex="0"
|
|
31
39
|
type="button"
|
|
32
40
|
>
|
|
33
41
|
<span
|
|
@@ -94,11 +102,17 @@ exports[`Dropdown widget should snapshot: initial render 1`] = `
|
|
|
94
102
|
<div
|
|
95
103
|
class="default_xu2jcg-o_O-menuWrapper_wvrnr4"
|
|
96
104
|
>
|
|
105
|
+
<span
|
|
106
|
+
aria-atomic="true"
|
|
107
|
+
aria-live="polite"
|
|
108
|
+
aria-relevant="additions text"
|
|
109
|
+
class="srOnly_19bpjuy"
|
|
110
|
+
data-test-id="dropdown-live-region"
|
|
111
|
+
/>
|
|
97
112
|
<button
|
|
98
113
|
aria-expanded="false"
|
|
99
114
|
aria-haspopup="listbox"
|
|
100
115
|
class="button_vr44p2-o_O-shared_u51dsh-o_O-default_kjzwx1"
|
|
101
|
-
tabindex="0"
|
|
102
116
|
type="button"
|
|
103
117
|
>
|
|
104
118
|
<span
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
# `NewTooltip`: KA tooltip component
|
|
2
|
-
|
|
3
|
-
This is a wrapper around [Wonderblock's popover component](https://github.com/Khan/wonder-blocks). It is API compatiable with Perseus and remains for compatiability and legacy reasons. If you are anyone but the Perseus group at Khan Academy please use the wonderblocks component directly.
|