@primer/react 0.0.0-20260218180138 → 0.0.0-20260218182540
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 +4 -4
- package/dist/Button/Button.js +34 -11
- package/dist/Button/ButtonBase.d.ts.map +1 -1
- package/dist/Button/ButtonBase.js +9 -14
- package/dist/Button/IconButton.js +140 -51
- package/dist/Button/LinkButton.js +39 -11
- package/dist/SelectPanel/SelectPanel.d.ts.map +1 -1
- package/dist/SelectPanel/SelectPanel.js +32 -82
- package/dist/hooks/useSlots.d.ts +50 -6
- package/dist/hooks/useSlots.d.ts.map +1 -1
- package/dist/hooks/useSlots.js +114 -36
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @primer/react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-20260218182540
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -12,18 +12,18 @@
|
|
|
12
12
|
|
|
13
13
|
- [#7546](https://github.com/primer/react/pull/7546) [`86d6897`](https://github.com/primer/react/commit/86d68971a602be6c99535eb01227bf48dd87cfdc) Thanks [@hectahertz](https://github.com/hectahertz)! - perf(Announce): skip getComputedStyle when there is no text content to announce
|
|
14
14
|
|
|
15
|
+
- [#7552](https://github.com/primer/react/pull/7552) [`551ec63`](https://github.com/primer/react/commit/551ec6338af5c45e3f549245d85a4dd5a708df47) Thanks [@hectahertz](https://github.com/hectahertz)! - perf(Button): fix CounterLabel remount and remove conditional DEV hook
|
|
16
|
+
|
|
15
17
|
- [#7504](https://github.com/primer/react/pull/7504) [`d91e78e`](https://github.com/primer/react/commit/d91e78e8d1e69915222354b95d09d93d269dbd8b) Thanks [@TylerJDev](https://github.com/TylerJDev)! - UnderlineNav: Adds `overflow: hidden` when the "More" button isn't present
|
|
16
18
|
|
|
17
19
|
- [#7526](https://github.com/primer/react/pull/7526) [`0c2358a`](https://github.com/primer/react/commit/0c2358aa12a409f7cbcf15ce4fd41cbb9eee4b6c) Thanks [@hectahertz](https://github.com/hectahertz)! - Add `content-visibility: auto` to ActionList items to improve rendering performance for large lists by allowing the browser to skip layout and paint for off-screen items.
|
|
18
20
|
|
|
19
21
|
- Fake entry to force publishing
|
|
20
22
|
|
|
21
|
-
- [#
|
|
23
|
+
- [#7555](https://github.com/primer/react/pull/7555) [`91ac722`](https://github.com/primer/react/commit/91ac722ad4d2706d15d984aa5985aaf172911ce5) Thanks [@hectahertz](https://github.com/hectahertz)! - perf(useSlots): short-circuit iteration and skip filled slots
|
|
22
24
|
|
|
23
25
|
- [#7548](https://github.com/primer/react/pull/7548) [`d4b32c3`](https://github.com/primer/react/commit/d4b32c3672d3d5421711324654c1028527dcdf38) Thanks [@hectahertz](https://github.com/hectahertz)! - perf(useIsMacOS): replace useState+useEffect with useSyncExternalStore to eliminate unnecessary re-render
|
|
24
26
|
|
|
25
|
-
- [#7497](https://github.com/primer/react/pull/7497) [`0b696cc`](https://github.com/primer/react/commit/0b696cc75435b01aacc15e81396fe26e5901c01b) Thanks [@hectahertz](https://github.com/hectahertz)! - Improve SelectPanel performance
|
|
26
|
-
|
|
27
27
|
## 38.12.0
|
|
28
28
|
|
|
29
29
|
### Minor Changes
|
package/dist/Button/Button.js
CHANGED
|
@@ -1,18 +1,41 @@
|
|
|
1
|
+
import { c } from 'react-compiler-runtime';
|
|
1
2
|
import { forwardRef } from 'react';
|
|
2
3
|
import { ButtonBase } from './ButtonBase.js';
|
|
3
4
|
import { jsx } from 'react/jsx-runtime';
|
|
4
5
|
|
|
5
|
-
const ButtonComponent = /*#__PURE__*/forwardRef(({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
const ButtonComponent = /*#__PURE__*/forwardRef((t0, forwardedRef) => {
|
|
7
|
+
const $ = c(7);
|
|
8
|
+
let children;
|
|
9
|
+
let props;
|
|
10
|
+
if ($[0] !== t0) {
|
|
11
|
+
({
|
|
12
|
+
children,
|
|
13
|
+
...props
|
|
14
|
+
} = t0);
|
|
15
|
+
$[0] = t0;
|
|
16
|
+
$[1] = children;
|
|
17
|
+
$[2] = props;
|
|
18
|
+
} else {
|
|
19
|
+
children = $[1];
|
|
20
|
+
props = $[2];
|
|
21
|
+
}
|
|
22
|
+
let t1;
|
|
23
|
+
if ($[3] !== children || $[4] !== forwardedRef || $[5] !== props) {
|
|
24
|
+
t1 = /*#__PURE__*/jsx(ButtonBase, {
|
|
25
|
+
ref: forwardedRef,
|
|
26
|
+
as: "button",
|
|
27
|
+
type: "button",
|
|
28
|
+
...props,
|
|
29
|
+
children: children
|
|
30
|
+
});
|
|
31
|
+
$[3] = children;
|
|
32
|
+
$[4] = forwardedRef;
|
|
33
|
+
$[5] = props;
|
|
34
|
+
$[6] = t1;
|
|
35
|
+
} else {
|
|
36
|
+
t1 = $[6];
|
|
37
|
+
}
|
|
38
|
+
return t1;
|
|
16
39
|
});
|
|
17
40
|
ButtonComponent.displayName = 'Button';
|
|
18
41
|
ButtonComponent.__SLOT__ = Symbol('Button');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ButtonBase.d.ts","sourceRoot":"","sources":["../../src/Button/ButtonBase.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,mBAAmB,IAAI,8BAA8B,EAAC,MAAM,sBAAsB,CAAA;AAC/F,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAA;AA2BxC,QAAA,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"ButtonBase.d.ts","sourceRoot":"","sources":["../../src/Button/ButtonBase.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,mBAAmB,IAAI,8BAA8B,EAAC,MAAM,sBAAsB,CAAA;AAC/F,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAA;AA2BxC,QAAA,MAAM,UAAU,EA2JV,8BAA8B,CAAC,QAAQ,GAAG,GAAG,EAAE,WAAW,CAAC,CAAA;AAEjE,OAAO,EAAC,UAAU,EAAC,CAAA"}
|
|
@@ -53,19 +53,14 @@ const ButtonBase = /*#__PURE__*/forwardRef(({
|
|
|
53
53
|
// Only include the loading aria-describedby if there is a loading state
|
|
54
54
|
const ariaDescribedByIds = loading ? [loadingAnnouncementID, ariaDescribedBy] : [ariaDescribedBy];
|
|
55
55
|
if (process.env.NODE_ENV !== "production") {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (innerRef.current && !(innerRef.current instanceof HTMLButtonElement) && !(innerRef.current instanceof HTMLAnchorElement) && !(innerRef.current.tagName === 'SUMMARY')) {
|
|
65
|
-
// eslint-disable-next-line no-console
|
|
66
|
-
console.warn('This component should be an instanceof a semantic button or anchor');
|
|
67
|
-
}
|
|
68
|
-
}, [innerRef]);
|
|
56
|
+
// Validate that the element is a semantic button/anchor.
|
|
57
|
+
// This runs during render (not in an effect) to avoid a conditional hook call
|
|
58
|
+
// that prevents React Compiler from optimizing this component.
|
|
59
|
+
const el = innerRef.current;
|
|
60
|
+
if (el && !(el instanceof HTMLButtonElement) && !(el instanceof HTMLAnchorElement) && !(el.tagName === 'SUMMARY')) {
|
|
61
|
+
// eslint-disable-next-line no-console
|
|
62
|
+
console.warn('This component should be an instanceof a semantic button or anchor');
|
|
63
|
+
}
|
|
69
64
|
}
|
|
70
65
|
return /*#__PURE__*/jsxs(ConditionalWrapper
|
|
71
66
|
// If anything is passed to `loading`, we need the wrapper:
|
|
@@ -125,7 +120,7 @@ const ButtonBase = /*#__PURE__*/forwardRef(({
|
|
|
125
120
|
- the button is in a loading state
|
|
126
121
|
- there is no leading visual to replace with a loading spinner
|
|
127
122
|
*/
|
|
128
|
-
count !== undefined && !TrailingVisual ? renderModuleVisual(
|
|
123
|
+
count !== undefined && !TrailingVisual ? renderModuleVisual(/*#__PURE__*/jsx(CounterLabel, {
|
|
129
124
|
className: classes.CounterLabel,
|
|
130
125
|
"data-component": "ButtonCounter",
|
|
131
126
|
children: count
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { c } from 'react-compiler-runtime';
|
|
1
2
|
import React, { forwardRef } from 'react';
|
|
2
3
|
import { ButtonBase } from './ButtonBase.js';
|
|
3
4
|
import { TooltipContext, Tooltip } from '../TooltipV2/Tooltip.js';
|
|
@@ -6,70 +7,158 @@ import classes from './ButtonBase.module.css.js';
|
|
|
6
7
|
import { clsx } from 'clsx';
|
|
7
8
|
import { jsx } from 'react/jsx-runtime';
|
|
8
9
|
|
|
9
|
-
const IconButton = /*#__PURE__*/forwardRef(({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
keyshortcuts
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
const IconButton = /*#__PURE__*/forwardRef((t0, forwardedRef) => {
|
|
11
|
+
const $ = c(36);
|
|
12
|
+
let Icon;
|
|
13
|
+
let ariaLabel;
|
|
14
|
+
let className;
|
|
15
|
+
let description;
|
|
16
|
+
let disabled;
|
|
17
|
+
let keybindingHint;
|
|
18
|
+
let keyshortcuts;
|
|
19
|
+
let props;
|
|
20
|
+
let t1;
|
|
21
|
+
let tooltipDirection;
|
|
22
|
+
if ($[0] !== t0) {
|
|
23
|
+
({
|
|
24
|
+
icon: Icon,
|
|
25
|
+
"aria-label": ariaLabel,
|
|
26
|
+
description,
|
|
27
|
+
disabled,
|
|
28
|
+
tooltipDirection,
|
|
29
|
+
unsafeDisableTooltip: t1,
|
|
30
|
+
keyshortcuts,
|
|
31
|
+
keybindingHint,
|
|
32
|
+
className,
|
|
33
|
+
...props
|
|
34
|
+
} = t0);
|
|
35
|
+
$[0] = t0;
|
|
36
|
+
$[1] = Icon;
|
|
37
|
+
$[2] = ariaLabel;
|
|
38
|
+
$[3] = className;
|
|
39
|
+
$[4] = description;
|
|
40
|
+
$[5] = disabled;
|
|
41
|
+
$[6] = keybindingHint;
|
|
42
|
+
$[7] = keyshortcuts;
|
|
43
|
+
$[8] = props;
|
|
44
|
+
$[9] = t1;
|
|
45
|
+
$[10] = tooltipDirection;
|
|
46
|
+
} else {
|
|
47
|
+
Icon = $[1];
|
|
48
|
+
ariaLabel = $[2];
|
|
49
|
+
className = $[3];
|
|
50
|
+
description = $[4];
|
|
51
|
+
disabled = $[5];
|
|
52
|
+
keybindingHint = $[6];
|
|
53
|
+
keyshortcuts = $[7];
|
|
54
|
+
props = $[8];
|
|
55
|
+
t1 = $[9];
|
|
56
|
+
tooltipDirection = $[10];
|
|
57
|
+
}
|
|
58
|
+
const unsafeDisableTooltip = t1 === undefined ? false : t1;
|
|
23
59
|
const {
|
|
24
60
|
tooltipId
|
|
25
|
-
} = React.useContext(TooltipContext);
|
|
61
|
+
} = React.useContext(TooltipContext);
|
|
26
62
|
const {
|
|
27
63
|
tooltipId: tooltipIdV1
|
|
28
|
-
} = React.useContext(TooltipContext$1);
|
|
29
|
-
|
|
64
|
+
} = React.useContext(TooltipContext$1);
|
|
30
65
|
const {
|
|
31
|
-
|
|
32
|
-
|
|
66
|
+
"aria-expanded": isExpanded,
|
|
67
|
+
"aria-haspopup": hasPopup
|
|
33
68
|
} = props;
|
|
34
69
|
const hasExternalTooltip = tooltipId || tooltipIdV1;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// This is mostly for `ActionMenu`, but could be applicable elsewhere.
|
|
38
|
-
const hasActivePopup = (isExpanded === true || isExpanded === 'true') && hasPopup === 'true';
|
|
39
|
-
const withoutTooltip = unsafeDisableTooltip || disabled || ariaLabel === undefined || ariaLabel === '' || hasExternalTooltip;
|
|
70
|
+
const hasActivePopup = (isExpanded === true || isExpanded === "true") && hasPopup === "true";
|
|
71
|
+
const withoutTooltip = unsafeDisableTooltip || disabled || ariaLabel === undefined || ariaLabel === "" || hasExternalTooltip;
|
|
40
72
|
if (withoutTooltip) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
73
|
+
let t2;
|
|
74
|
+
if ($[11] !== className) {
|
|
75
|
+
t2 = clsx(className, classes.IconButton);
|
|
76
|
+
$[11] = className;
|
|
77
|
+
$[12] = t2;
|
|
78
|
+
} else {
|
|
79
|
+
t2 = $[12];
|
|
80
|
+
}
|
|
81
|
+
let t3;
|
|
82
|
+
if ($[13] !== Icon || $[14] !== ariaLabel || $[15] !== disabled || $[16] !== forwardedRef || $[17] !== props || $[18] !== t2) {
|
|
83
|
+
t3 = /*#__PURE__*/jsx(ButtonBase, {
|
|
84
|
+
icon: Icon,
|
|
85
|
+
className: t2,
|
|
86
|
+
"data-component": "IconButton",
|
|
87
|
+
type: "button",
|
|
88
|
+
"aria-label": ariaLabel,
|
|
89
|
+
disabled: disabled,
|
|
90
|
+
...props,
|
|
91
|
+
ref: forwardedRef
|
|
92
|
+
});
|
|
93
|
+
$[13] = Icon;
|
|
94
|
+
$[14] = ariaLabel;
|
|
95
|
+
$[15] = disabled;
|
|
96
|
+
$[16] = forwardedRef;
|
|
97
|
+
$[17] = props;
|
|
98
|
+
$[18] = t2;
|
|
99
|
+
$[19] = t3;
|
|
100
|
+
} else {
|
|
101
|
+
t3 = $[19];
|
|
102
|
+
}
|
|
103
|
+
return t3;
|
|
52
104
|
} else {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
105
|
+
var _description, _keybindingHint, _keyshortcuts;
|
|
106
|
+
const tooltipText = (_description = description) !== null && _description !== void 0 ? _description : ariaLabel;
|
|
107
|
+
const t2 = description ? undefined : "label";
|
|
108
|
+
const t3 = (_keybindingHint = keybindingHint) !== null && _keybindingHint !== void 0 ? _keybindingHint : keyshortcuts;
|
|
109
|
+
let t4;
|
|
110
|
+
if ($[20] !== className) {
|
|
111
|
+
t4 = clsx(className, classes.IconButton);
|
|
112
|
+
$[20] = className;
|
|
113
|
+
$[21] = t4;
|
|
114
|
+
} else {
|
|
115
|
+
t4 = $[21];
|
|
116
|
+
}
|
|
117
|
+
const t5 = (_keyshortcuts = keyshortcuts) !== null && _keyshortcuts !== void 0 ? _keyshortcuts : undefined;
|
|
118
|
+
const t6 = description ? ariaLabel : undefined;
|
|
119
|
+
let t7;
|
|
120
|
+
if ($[22] !== Icon || $[23] !== props || $[24] !== t4 || $[25] !== t5 || $[26] !== t6) {
|
|
121
|
+
t7 = /*#__PURE__*/jsx(ButtonBase, {
|
|
62
122
|
icon: Icon,
|
|
63
|
-
className:
|
|
123
|
+
className: t4,
|
|
64
124
|
"data-component": "IconButton",
|
|
65
125
|
type: "button",
|
|
66
|
-
"aria-keyshortcuts":
|
|
67
|
-
|
|
68
|
-
,
|
|
69
|
-
"aria-label": description ? ariaLabel : undefined,
|
|
126
|
+
"aria-keyshortcuts": t5,
|
|
127
|
+
"aria-label": t6,
|
|
70
128
|
...props
|
|
71
|
-
})
|
|
72
|
-
|
|
129
|
+
});
|
|
130
|
+
$[22] = Icon;
|
|
131
|
+
$[23] = props;
|
|
132
|
+
$[24] = t4;
|
|
133
|
+
$[25] = t5;
|
|
134
|
+
$[26] = t6;
|
|
135
|
+
$[27] = t7;
|
|
136
|
+
} else {
|
|
137
|
+
t7 = $[27];
|
|
138
|
+
}
|
|
139
|
+
let t8;
|
|
140
|
+
if ($[28] !== forwardedRef || $[29] !== hasActivePopup || $[30] !== t2 || $[31] !== t3 || $[32] !== t7 || $[33] !== tooltipDirection || $[34] !== tooltipText) {
|
|
141
|
+
t8 = /*#__PURE__*/jsx(Tooltip, {
|
|
142
|
+
ref: forwardedRef,
|
|
143
|
+
text: tooltipText,
|
|
144
|
+
type: t2,
|
|
145
|
+
direction: tooltipDirection,
|
|
146
|
+
keybindingHint: t3,
|
|
147
|
+
_privateDisableTooltip: hasActivePopup,
|
|
148
|
+
children: t7
|
|
149
|
+
});
|
|
150
|
+
$[28] = forwardedRef;
|
|
151
|
+
$[29] = hasActivePopup;
|
|
152
|
+
$[30] = t2;
|
|
153
|
+
$[31] = t3;
|
|
154
|
+
$[32] = t7;
|
|
155
|
+
$[33] = tooltipDirection;
|
|
156
|
+
$[34] = tooltipText;
|
|
157
|
+
$[35] = t8;
|
|
158
|
+
} else {
|
|
159
|
+
t8 = $[35];
|
|
160
|
+
}
|
|
161
|
+
return t8;
|
|
73
162
|
}
|
|
74
163
|
});
|
|
75
164
|
|
|
@@ -1,18 +1,46 @@
|
|
|
1
|
+
import { c } from 'react-compiler-runtime';
|
|
1
2
|
import { forwardRef } from 'react';
|
|
2
3
|
import { ButtonBase } from './ButtonBase.js';
|
|
3
4
|
import { jsx } from 'react/jsx-runtime';
|
|
4
5
|
|
|
5
|
-
const LinkButton = /*#__PURE__*/forwardRef(({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
const LinkButton = /*#__PURE__*/forwardRef((t0, forwardedRef) => {
|
|
7
|
+
const $ = c(9);
|
|
8
|
+
let children;
|
|
9
|
+
let props;
|
|
10
|
+
let t1;
|
|
11
|
+
if ($[0] !== t0) {
|
|
12
|
+
({
|
|
13
|
+
children,
|
|
14
|
+
as: t1,
|
|
15
|
+
...props
|
|
16
|
+
} = t0);
|
|
17
|
+
$[0] = t0;
|
|
18
|
+
$[1] = children;
|
|
19
|
+
$[2] = props;
|
|
20
|
+
$[3] = t1;
|
|
21
|
+
} else {
|
|
22
|
+
children = $[1];
|
|
23
|
+
props = $[2];
|
|
24
|
+
t1 = $[3];
|
|
25
|
+
}
|
|
26
|
+
const Component = t1 === undefined ? "a" : t1;
|
|
27
|
+
let t2;
|
|
28
|
+
if ($[4] !== Component || $[5] !== children || $[6] !== forwardedRef || $[7] !== props) {
|
|
29
|
+
t2 = /*#__PURE__*/jsx(ButtonBase, {
|
|
30
|
+
as: Component,
|
|
31
|
+
ref: forwardedRef,
|
|
32
|
+
...props,
|
|
33
|
+
children: children
|
|
34
|
+
});
|
|
35
|
+
$[4] = Component;
|
|
36
|
+
$[5] = children;
|
|
37
|
+
$[6] = forwardedRef;
|
|
38
|
+
$[7] = props;
|
|
39
|
+
$[8] = t2;
|
|
40
|
+
} else {
|
|
41
|
+
t2 = $[8];
|
|
42
|
+
}
|
|
43
|
+
return t2;
|
|
16
44
|
});
|
|
17
45
|
|
|
18
46
|
export { LinkButton };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectPanel.d.ts","sourceRoot":"","sources":["../../src/SelectPanel/SelectPanel.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,SAAS,EAAC,MAAM,wBAAwB,CAAA;AAC1F,OAAO,KAAK,EAAE,EAA+E,KAAK,GAAG,EAAC,MAAM,OAAO,CAAA;AACnH,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,oBAAoB,CAAA;AAE5D,OAAO,KAAK,EAAC,iCAAiC,EAAC,MAAM,oCAAoC,CAAA;AACzF,OAAO,KAAK,EAAC,uBAAuB,EAAC,MAAM,uBAAuB,CAAA;AAGlE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,YAAY,CAAA;AAE5C,OAAO,KAAK,EAAY,SAAS,EAAC,MAAM,IAAI,CAAA;AAiB5C,OAAO,KAAK,EAAC,WAAW,EAAE,eAAe,EAAC,MAAM,iBAAiB,CAAA;AAiCjE,UAAU,0BAA0B;IAClC,QAAQ,EAAE,SAAS,GAAG,SAAS,CAAA;IAC/B,gBAAgB,EAAE,CAAC,QAAQ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AC,WAAW,CAM1C,CAAA;AAED,QAAA,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,GAAG,WAAW,CAM1D,CAAA;AAED,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;CAItB,CAAA"}
|
|
@@ -132,6 +132,8 @@ function Panel({
|
|
|
132
132
|
wide: false
|
|
133
133
|
}, false);
|
|
134
134
|
const [selectedOnSort, setSelectedOnSort] = useState([]);
|
|
135
|
+
const [prevItems, setPrevItems] = useState([]);
|
|
136
|
+
const [prevOpen, setPrevOpen] = useState(open);
|
|
135
137
|
const initialHeightRef = useRef(0);
|
|
136
138
|
const initialScaleRef = useRef(1);
|
|
137
139
|
const noticeRef = useRef(null);
|
|
@@ -203,19 +205,6 @@ function Panel({
|
|
|
203
205
|
resetSort();
|
|
204
206
|
}
|
|
205
207
|
}, [loadingManagedInternally, externalOnFilterChange, setInternalFilterValue, dataLoadedOnce, safeSetTimeout, safeClearTimeout, items.length, resetSort]);
|
|
206
|
-
|
|
207
|
-
// Pre-compute a Set of item IDs in the current filtered view for O(1) lookups
|
|
208
|
-
const itemsInViewSet = useMemo(() => {
|
|
209
|
-
const set = new Set();
|
|
210
|
-
for (const item of items) {
|
|
211
|
-
if (item.id !== undefined) {
|
|
212
|
-
set.add(item.id);
|
|
213
|
-
} else {
|
|
214
|
-
set.add(item);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return set;
|
|
218
|
-
}, [items]);
|
|
219
208
|
const handleSelectAllChange = useCallback(checked => {
|
|
220
209
|
// Exit early if not in multi-select mode
|
|
221
210
|
if (!isMultiSelectVariant(selected)) {
|
|
@@ -223,20 +212,13 @@ function Panel({
|
|
|
223
212
|
}
|
|
224
213
|
const multiSelectOnChange = onSelectedChange;
|
|
225
214
|
const selectedArray = selected;
|
|
226
|
-
|
|
227
|
-
// Use Set for O(1) lookup instead of O(n) items.some()
|
|
228
|
-
const selectedItemsNotInFilteredView = selectedArray.filter(selectedItem => {
|
|
229
|
-
if (selectedItem.id !== undefined) {
|
|
230
|
-
return !itemsInViewSet.has(selectedItem.id);
|
|
231
|
-
}
|
|
232
|
-
return !itemsInViewSet.has(selectedItem);
|
|
233
|
-
});
|
|
215
|
+
const selectedItemsNotInFilteredView = selectedArray.filter(selectedItem => !items.some(item => areItemsEqual(item, selectedItem)));
|
|
234
216
|
if (checked) {
|
|
235
217
|
multiSelectOnChange([...selectedItemsNotInFilteredView, ...items]);
|
|
236
218
|
} else {
|
|
237
219
|
multiSelectOnChange(selectedItemsNotInFilteredView);
|
|
238
220
|
}
|
|
239
|
-
}, [items,
|
|
221
|
+
}, [items, onSelectedChange, selected]);
|
|
240
222
|
|
|
241
223
|
// disable body scroll when the panel is open on narrow screens
|
|
242
224
|
useEffect(() => {
|
|
@@ -402,29 +384,10 @@ function Panel({
|
|
|
402
384
|
});
|
|
403
385
|
};
|
|
404
386
|
}, [placeholder, renderAnchor, selected]);
|
|
405
|
-
|
|
406
|
-
// Pre-compute a Set of selected item IDs/references for O(1) lookups
|
|
407
|
-
// This optimizes isItemCurrentlySelected from O(m) to O(1) per call
|
|
408
|
-
const selectedItemsSet = useMemo(() => {
|
|
409
|
-
const set = new Set();
|
|
410
|
-
if (isMultiSelectVariant(selected)) {
|
|
411
|
-
for (const item of selected) {
|
|
412
|
-
if (item.id !== undefined) {
|
|
413
|
-
set.add(item.id);
|
|
414
|
-
} else {
|
|
415
|
-
set.add(item);
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
return set;
|
|
420
|
-
}, [selected]);
|
|
421
387
|
const isItemCurrentlySelected = useCallback(item => {
|
|
422
|
-
// For multi-select,
|
|
388
|
+
// For multi-select, we just need to check if the item is in the selected array
|
|
423
389
|
if (isMultiSelectVariant(selected)) {
|
|
424
|
-
|
|
425
|
-
return selectedItemsSet.has(item.id);
|
|
426
|
-
}
|
|
427
|
-
return selectedItemsSet.has(item);
|
|
390
|
+
return doesItemsIncludeItem(selected, item);
|
|
428
391
|
}
|
|
429
392
|
|
|
430
393
|
// For single-select modal, there is an intermediate state when the user has selected
|
|
@@ -435,24 +398,8 @@ function Panel({
|
|
|
435
398
|
|
|
436
399
|
// For single-select anchored, we just need to check if the item is the selected item
|
|
437
400
|
return (selected === null || selected === void 0 ? void 0 : selected.id) !== undefined ? selected.id === item.id : selected === item;
|
|
438
|
-
}, [selected,
|
|
401
|
+
}, [selected, intermediateSelected, isSingleSelectModal]);
|
|
439
402
|
const itemsToRender = useMemo(() => {
|
|
440
|
-
// Pre-compute a Set of selected item IDs/references for O(1) lookups during sorting
|
|
441
|
-
// This avoids O(m * k) work per comparison in the sort function
|
|
442
|
-
const selectedOnSortSet = new Set();
|
|
443
|
-
for (const item of selectedOnSort) {
|
|
444
|
-
if (item.id !== undefined) {
|
|
445
|
-
selectedOnSortSet.add(item.id);
|
|
446
|
-
} else {
|
|
447
|
-
selectedOnSortSet.add(item);
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
const isSelectedForSort = item => {
|
|
451
|
-
if (item.id !== undefined) {
|
|
452
|
-
return selectedOnSortSet.has(item.id);
|
|
453
|
-
}
|
|
454
|
-
return selectedOnSortSet.has(item);
|
|
455
|
-
};
|
|
456
403
|
return items.map(item => {
|
|
457
404
|
return {
|
|
458
405
|
...item,
|
|
@@ -489,39 +436,42 @@ function Panel({
|
|
|
489
436
|
};
|
|
490
437
|
}).sort((itemA, itemB) => {
|
|
491
438
|
if (shouldOrderSelectedFirst) {
|
|
492
|
-
|
|
493
|
-
const
|
|
439
|
+
// itemA is selected (for sorting purposes) if an object in selectedOnSort matches every property of itemA, except for the selected property
|
|
440
|
+
const itemASelected = selectedOnSort.some(item => Object.entries(item).every(([key, value]) => {
|
|
441
|
+
if (key === 'selected') {
|
|
442
|
+
return true;
|
|
443
|
+
}
|
|
444
|
+
return itemA[key] === value;
|
|
445
|
+
}));
|
|
446
|
+
|
|
447
|
+
// itemB is selected (for sorting purposes) if an object in selectedOnSort matches every property of itemA, except for the selected property
|
|
448
|
+
const itemBSelected = selectedOnSort.some(item => Object.entries(item).every(([key, value]) => {
|
|
449
|
+
if (key === 'selected') {
|
|
450
|
+
return true;
|
|
451
|
+
}
|
|
452
|
+
return itemB[key] === value;
|
|
453
|
+
}));
|
|
494
454
|
|
|
495
455
|
// order selected items first
|
|
496
|
-
if (itemASelected
|
|
456
|
+
if (itemASelected > itemBSelected) {
|
|
497
457
|
return -1;
|
|
498
|
-
} else if (
|
|
458
|
+
} else if (itemASelected < itemBSelected) {
|
|
499
459
|
return 1;
|
|
500
460
|
}
|
|
501
461
|
}
|
|
502
462
|
return 0;
|
|
503
463
|
});
|
|
504
464
|
}, [onClose, onSelectedChange, items, selected, isItemCurrentlySelected, isSingleSelectModal, intermediateSelected, shouldOrderSelectedFirst, selectedOnSort]);
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
useEffect(() => {
|
|
509
|
-
if (prevItemsRef.current !== items) {
|
|
510
|
-
if (prevItemsRef.current.length === 0 && items.length > 0) {
|
|
511
|
-
resetSort();
|
|
512
|
-
}
|
|
513
|
-
prevItemsRef.current = items;
|
|
514
|
-
}
|
|
515
|
-
}, [items, resetSort]);
|
|
516
|
-
|
|
517
|
-
// Reset sort when panel opens
|
|
518
|
-
const prevOpenRef = useRef(open);
|
|
519
|
-
useEffect(() => {
|
|
520
|
-
if (prevOpenRef.current !== open) {
|
|
465
|
+
if (prevItems !== items) {
|
|
466
|
+
setPrevItems(items);
|
|
467
|
+
if (prevItems.length === 0 && items.length > 0) {
|
|
521
468
|
resetSort();
|
|
522
|
-
prevOpenRef.current = open;
|
|
523
469
|
}
|
|
524
|
-
}
|
|
470
|
+
}
|
|
471
|
+
if (open !== prevOpen) {
|
|
472
|
+
setPrevOpen(open);
|
|
473
|
+
resetSort();
|
|
474
|
+
}
|
|
525
475
|
const focusTrapSettings = {
|
|
526
476
|
initialFocusRef: inputRef || undefined
|
|
527
477
|
};
|
package/dist/hooks/useSlots.d.ts
CHANGED
|
@@ -1,8 +1,56 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* useSlots - Extract slot components from children for SSR-compatible slot APIs.
|
|
4
|
+
*
|
|
5
|
+
* Given a list of children and a config mapping slot names to component types,
|
|
6
|
+
* separates children into two groups: matched slots and the rest.
|
|
7
|
+
*
|
|
8
|
+
* Config: { leadingVisual: LeadingVisual, description: Description }
|
|
9
|
+
*
|
|
10
|
+
* Children: Matching: Output:
|
|
11
|
+
* +----------------+ slots = {
|
|
12
|
+
* | LeadingVisual | -> matches slot 0 --> leadingVisual: <LeadingVisual />
|
|
13
|
+
* | "Project name" | -> no match --> description: <Description />
|
|
14
|
+
* | Description | -> matches slot 1 --> }
|
|
15
|
+
* | TrailingVisual | -> no match --> rest = ["Project name", <TrailingVisual />]
|
|
16
|
+
* +----------------+
|
|
17
|
+
*
|
|
18
|
+
* Performance-sensitive: called per item in lists (e.g. 100-item ActionList
|
|
19
|
+
* calls this 101 times per render).
|
|
20
|
+
*
|
|
21
|
+
* Once all slots are filled, remaining children skip matching entirely in
|
|
22
|
+
* production (single integer comparison). In dev, we still scan for duplicates
|
|
23
|
+
* to emit a warning.
|
|
24
|
+
*
|
|
25
|
+
* Flow per child:
|
|
26
|
+
*
|
|
27
|
+
* child ──> isValidElement? ──no──> rest[]
|
|
28
|
+
* |
|
|
29
|
+
* yes
|
|
30
|
+
* |
|
|
31
|
+
* v
|
|
32
|
+
* all slots filled? ──yes──> rest[] (prod)
|
|
33
|
+
* | |
|
|
34
|
+
* no [dev: check for
|
|
35
|
+
* | duplicate warning]
|
|
36
|
+
* v
|
|
37
|
+
* match against unfilled slots
|
|
38
|
+
* |
|
|
39
|
+
* found match? ──no──> rest[]
|
|
40
|
+
* |
|
|
41
|
+
* yes
|
|
42
|
+
* |
|
|
43
|
+
* v
|
|
44
|
+
* slots[key] = child, slotsFound++
|
|
45
|
+
*
|
|
46
|
+
* Slot config supports two matcher styles:
|
|
47
|
+
* 1. Component reference: { visual: LeadingVisual }
|
|
48
|
+
* 2. Component + test fn: { block: [Description, props => props.variant === 'block'] }
|
|
49
|
+
*/
|
|
50
|
+
type Props = any;
|
|
2
51
|
type ComponentMatcher = React.ElementType<Props>;
|
|
3
52
|
type ComponentAndPropsMatcher = [ComponentMatcher, (props: Props) => boolean];
|
|
4
53
|
export type SlotConfig = Record<string, ComponentMatcher | ComponentAndPropsMatcher>;
|
|
5
|
-
type Props = any;
|
|
6
54
|
type SlotElements<Config extends SlotConfig> = {
|
|
7
55
|
[Property in keyof Config]: SlotValue<Config, Property>;
|
|
8
56
|
};
|
|
@@ -10,11 +58,7 @@ type SlotValue<Config, Property extends keyof Config> = Config[Property] extends
|
|
|
10
58
|
infer ElementType extends React.ElementType,
|
|
11
59
|
infer _testFn
|
|
12
60
|
] ? React.ReactElement<React.ComponentPropsWithoutRef<ElementType>, ElementType> : never;
|
|
13
|
-
/**
|
|
14
|
-
* Extract components from `children` so we can render them in different places,
|
|
15
|
-
* allowing us to implement components with SSR-compatible slot APIs.
|
|
16
|
-
* Note: We can only extract direct children, not nested ones.
|
|
17
|
-
*/
|
|
61
|
+
/** Extract slot components from children. See file header for details. */
|
|
18
62
|
export declare function useSlots<Config extends SlotConfig>(children: React.ReactNode, config: Config): [Partial<SlotElements<Config>>, React.ReactNode[]];
|
|
19
63
|
export {};
|
|
20
64
|
//# sourceMappingURL=useSlots.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSlots.d.ts","sourceRoot":"","sources":["../../src/hooks/useSlots.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"useSlots.d.ts","sourceRoot":"","sources":["../../src/hooks/useSlots.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAKzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AAKH,KAAK,KAAK,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
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* useSlots - Extract slot components from children for SSR-compatible slot APIs.
|
|
7
|
+
*
|
|
8
|
+
* Given a list of children and a config mapping slot names to component types,
|
|
9
|
+
* separates children into two groups: matched slots and the rest.
|
|
10
|
+
*
|
|
11
|
+
* Config: { leadingVisual: LeadingVisual, description: Description }
|
|
12
|
+
*
|
|
13
|
+
* Children: Matching: Output:
|
|
14
|
+
* +----------------+ slots = {
|
|
15
|
+
* | LeadingVisual | -> matches slot 0 --> leadingVisual: <LeadingVisual />
|
|
16
|
+
* | "Project name" | -> no match --> description: <Description />
|
|
17
|
+
* | Description | -> matches slot 1 --> }
|
|
18
|
+
* | TrailingVisual | -> no match --> rest = ["Project name", <TrailingVisual />]
|
|
19
|
+
* +----------------+
|
|
20
|
+
*
|
|
21
|
+
* Performance-sensitive: called per item in lists (e.g. 100-item ActionList
|
|
22
|
+
* calls this 101 times per render).
|
|
23
|
+
*
|
|
24
|
+
* Once all slots are filled, remaining children skip matching entirely in
|
|
25
|
+
* production (single integer comparison). In dev, we still scan for duplicates
|
|
26
|
+
* to emit a warning.
|
|
27
|
+
*
|
|
28
|
+
* Flow per child:
|
|
29
|
+
*
|
|
30
|
+
* child ──> isValidElement? ──no──> rest[]
|
|
31
|
+
* |
|
|
32
|
+
* yes
|
|
33
|
+
* |
|
|
34
|
+
* v
|
|
35
|
+
* all slots filled? ──yes──> rest[] (prod)
|
|
36
|
+
* | |
|
|
37
|
+
* no [dev: check for
|
|
38
|
+
* | duplicate warning]
|
|
39
|
+
* v
|
|
40
|
+
* match against unfilled slots
|
|
41
|
+
* |
|
|
42
|
+
* found match? ──no──> rest[]
|
|
43
|
+
* |
|
|
44
|
+
* yes
|
|
45
|
+
* |
|
|
46
|
+
* v
|
|
47
|
+
* slots[key] = child, slotsFound++
|
|
48
|
+
*
|
|
49
|
+
* Slot config supports two matcher styles:
|
|
50
|
+
* 1. Component reference: { visual: LeadingVisual }
|
|
51
|
+
* 2. Component + test fn: { block: [Description, props => props.variant === 'block'] }
|
|
52
|
+
*/
|
|
7
53
|
|
|
8
|
-
//
|
|
54
|
+
// --- Types ---
|
|
9
55
|
|
|
10
|
-
// We don't know what the props are yet, we set them later based on slot config
|
|
11
56
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
57
|
|
|
13
|
-
//
|
|
58
|
+
// --- Matching ---
|
|
14
59
|
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
60
|
+
/** Check if a child element matches a slot config entry, either by direct type comparison or slot symbol. */
|
|
61
|
+
function childMatchesSlot(child, slotValue) {
|
|
62
|
+
if (Array.isArray(slotValue)) {
|
|
63
|
+
const [component, testFn] = slotValue;
|
|
64
|
+
return (child.type === component || isSlot(child, component)) && testFn(child.props);
|
|
65
|
+
}
|
|
66
|
+
return child.type === slotValue || isSlot(child, slotValue);
|
|
67
|
+
}
|
|
23
68
|
|
|
24
|
-
|
|
69
|
+
// --- Hook ---
|
|
70
|
+
|
|
71
|
+
/** Extract slot components from children. See file header for details. */
|
|
72
|
+
function useSlots(children, config) {
|
|
25
73
|
const rest = [];
|
|
26
74
|
const keys = Object.keys(config);
|
|
27
75
|
const values = Object.values(config);
|
|
76
|
+
const totalSlots = keys.length;
|
|
77
|
+
|
|
78
|
+
// Initialize all slot keys to undefined so callers can check `slots.x === undefined`
|
|
79
|
+
const slots = {};
|
|
80
|
+
for (let i = 0; i < totalSlots; i++) {
|
|
81
|
+
slots[keys[i]] = undefined;
|
|
82
|
+
}
|
|
83
|
+
let slotsFound = 0;
|
|
28
84
|
|
|
29
85
|
// eslint-disable-next-line github/array-foreach
|
|
30
86
|
React.Children.forEach(children, child => {
|
|
@@ -32,41 +88,63 @@ function useSlots(children, config) {
|
|
|
32
88
|
rest.push(child);
|
|
33
89
|
return;
|
|
34
90
|
}
|
|
35
|
-
const index = values.findIndex(value => {
|
|
36
|
-
if (Array.isArray(value)) {
|
|
37
|
-
const [component, testFn] = value;
|
|
38
|
-
return (child.type === component || isSlot(child, component)) && testFn(child.props);
|
|
39
|
-
} else {
|
|
40
|
-
return child.type === value || isSlot(child, value);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
91
|
|
|
44
|
-
//
|
|
45
|
-
if (
|
|
92
|
+
// Short-circuit: all slots filled, no more matching needed
|
|
93
|
+
if (slotsFound === totalSlots) {
|
|
94
|
+
if (process.env.NODE_ENV !== "production" && warnIfDuplicate(child, keys, values, totalSlots)) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
46
97
|
rest.push(child);
|
|
47
98
|
return;
|
|
48
99
|
}
|
|
49
|
-
const slotKey = keys[index];
|
|
50
100
|
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
|
|
101
|
+
// Try to match child against a slot
|
|
102
|
+
const matchedIndex = findMatchingSlot(child, values, totalSlots);
|
|
103
|
+
if (matchedIndex === -1) {
|
|
104
|
+
rest.push(child);
|
|
54
105
|
return;
|
|
55
106
|
}
|
|
107
|
+
const slotKey = keys[matchedIndex];
|
|
56
108
|
|
|
57
|
-
//
|
|
58
|
-
|
|
109
|
+
// Duplicate: slot already filled by an earlier child
|
|
110
|
+
if (slots[slotKey] !== undefined) {
|
|
111
|
+
if (process.env.NODE_ENV !== "production") {
|
|
112
|
+
process.env.NODE_ENV !== "production" ? warning(true, `Found duplicate "${String(slotKey)}" slot. Only the first will be rendered.`) : void 0;
|
|
113
|
+
}
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
59
116
|
slots[slotKey] = child;
|
|
117
|
+
slotsFound++;
|
|
60
118
|
});
|
|
61
119
|
return [slots, rest];
|
|
62
120
|
}
|
|
63
121
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
122
|
+
// --- Helpers ---
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Find the first slot config entry matching this child.
|
|
126
|
+
* Returns the config index, or -1 if no match.
|
|
127
|
+
*/
|
|
128
|
+
function findMatchingSlot(child, values, totalSlots) {
|
|
129
|
+
for (let i = 0; i < totalSlots; i++) {
|
|
130
|
+
if (childMatchesSlot(child, values[i])) return i;
|
|
131
|
+
}
|
|
132
|
+
return -1;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Dev-only: check if a child duplicates an already-filled slot.
|
|
137
|
+
* Returns true (and warns) if a duplicate is found, false otherwise.
|
|
138
|
+
* Used in the short-circuit path where all slots are already filled.
|
|
139
|
+
*/
|
|
140
|
+
function warnIfDuplicate(child, keys, values, totalSlots) {
|
|
141
|
+
for (let i = 0; i < totalSlots; i++) {
|
|
142
|
+
if (childMatchesSlot(child, values[i])) {
|
|
143
|
+
process.env.NODE_ENV !== "production" ? warning(true, `Found duplicate "${String(keys[i])}" slot. Only the first will be rendered.`) : void 0;
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return false;
|
|
70
148
|
}
|
|
71
149
|
|
|
72
150
|
export { useSlots };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primer/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-
|
|
4
|
+
"version": "0.0.0-20260218182540",
|
|
5
5
|
"description": "An implementation of GitHub's Primer Design System using React",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -134,7 +134,7 @@
|
|
|
134
134
|
"@types/react-is": "18.3.1",
|
|
135
135
|
"@vitejs/plugin-react": "^4.3.3",
|
|
136
136
|
"afterframe": "^1.0.2",
|
|
137
|
-
"ajv": "8.
|
|
137
|
+
"ajv": "8.18.0",
|
|
138
138
|
"axe-core": "4.9.1",
|
|
139
139
|
"babel-core": "7.0.0-bridge.0",
|
|
140
140
|
"babel-plugin-add-react-displayname": "0.0.5",
|