@primer/react 0.0.0-20261109161837 → 0.0.0-20261112223856
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 -2
- package/dist/hooks/useAnchoredPosition.js +30 -17
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @primer/react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-20261112223856
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -18,9 +18,11 @@
|
|
|
18
18
|
|
|
19
19
|
- Fake entry to force publishing
|
|
20
20
|
|
|
21
|
+
- [#8725](https://github.com/primer/react/pull/8725) [`155203f`](https://github.com/primer/react/commit/155203f2eac0987a1e588d020c7969d284c9b01f) Thanks [@mattcosta7](https://github.com/mattcosta7)! - useAnchoredPosition: Skip re-renders when the overlay position is unchanged, and reposition when `side` or `align` changes while open. This reduces re-renders in ActionMenu, SelectPanel, Autocomplete and AnchoredOverlay.
|
|
22
|
+
|
|
21
23
|
- [#8628](https://github.com/primer/react/pull/8628) [`41f29c8`](https://github.com/primer/react/commit/41f29c845663936043618af29dcb71de4c9384b2) Thanks [@joshblack](https://github.com/joshblack)! - SkeletonAvatar, SkeletonText: Preserve the requested size and shape regardless of stylesheet load order
|
|
22
24
|
|
|
23
|
-
- [#8681](https://github.com/primer/react/pull/8681) [`
|
|
25
|
+
- [#8681](https://github.com/primer/react/pull/8681) [`8a9013e`](https://github.com/primer/react/commit/8a9013ea48359ad60a60e194783c865c08d3b7db) Thanks [@mattcosta7](https://github.com/mattcosta7)! - SkeletonBox, SkeletonText, SkeletonAvatar, ProgressBar: Run the loading shimmer animation on the compositor to reduce main-thread work while skeletons are visible
|
|
24
26
|
|
|
25
27
|
- [#8562](https://github.com/primer/react/pull/8562) [`ee46232`](https://github.com/primer/react/commit/ee46232fafa24701415b21eed60cca68e589cf1c) Thanks [@joshblack](https://github.com/joshblack)! - useOnEscapePress, useOnOutsideClick: Improve performance when callbacks change between renders.
|
|
26
28
|
|
|
@@ -38,38 +38,36 @@ function useAnchoredPosition(settings, dependencies = []) {
|
|
|
38
38
|
const enabled = (_settings$enabled = settings === null || settings === void 0 ? void 0 : settings.enabled) !== null && _settings$enabled !== void 0 ? _settings$enabled : true;
|
|
39
39
|
const savedOnPositionChange = React.useRef(settings === null || settings === void 0 ? void 0 : settings.onPositionChange);
|
|
40
40
|
const [position, setPosition] = React.useState(void 0);
|
|
41
|
-
const
|
|
41
|
+
const prevHeightRef = React.useRef(void 0);
|
|
42
42
|
const topPositionChanged = (prevPosition, newPosition) => {
|
|
43
43
|
return prevPosition && ["outside-top", "inside-top"].includes(prevPosition.anchorSide) && (prevPosition.anchorSide !== newPosition.anchorSide || prevPosition.top < newPosition.top);
|
|
44
44
|
};
|
|
45
|
-
const updateElementHeight = () => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
return prevHeight;
|
|
56
|
-
});
|
|
57
|
-
return heightUpdated;
|
|
45
|
+
const updateElementHeight = (prevHeight) => {
|
|
46
|
+
var _floatingElementRef$c, _floatingElementRef$c2;
|
|
47
|
+
if (prevHeight && prevHeight > ((_floatingElementRef$c = (_floatingElementRef$c2 = floatingElementRef.current) === null || _floatingElementRef$c2 === void 0 ? void 0 : _floatingElementRef$c2.clientHeight) !== null && _floatingElementRef$c !== void 0 ? _floatingElementRef$c : 0)) {
|
|
48
|
+
requestAnimationFrame(() => {
|
|
49
|
+
floatingElementRef.current.style.height = `${prevHeight}px`;
|
|
50
|
+
});
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
58
54
|
};
|
|
59
55
|
const updatePosition = React.useCallback(() => {
|
|
60
|
-
var _floatingElementRef$c5;
|
|
61
56
|
if (!enabled) return;
|
|
57
|
+
const prevMeasured = prevHeightRef.current;
|
|
58
|
+
const prevHeight = (prevMeasured === null || prevMeasured === void 0 ? void 0 : prevMeasured.element) === floatingElementRef.current ? prevMeasured.height : void 0;
|
|
62
59
|
if (floatingElementRef.current instanceof Element && anchorElementRef.current instanceof Element) {
|
|
63
60
|
const newPosition = getAnchoredPosition(floatingElementRef.current, anchorElementRef.current, settings);
|
|
64
61
|
setPosition((prev) => {
|
|
65
62
|
if (settings !== null && settings !== void 0 && settings.pinPosition && topPositionChanged(prev, newPosition)) {
|
|
66
63
|
var _anchorElementRef$cur, _anchorElementRef$cur2, _floatingElementRef$c3, _floatingElementRef$c4;
|
|
67
|
-
if (((_anchorElementRef$cur = (_anchorElementRef$cur2 = anchorElementRef.current) === null || _anchorElementRef$cur2 === void 0 ? void 0 : _anchorElementRef$cur2.getBoundingClientRect().top) !== null && _anchorElementRef$cur !== void 0 ? _anchorElementRef$cur : 0) > ((_floatingElementRef$c3 = (_floatingElementRef$c4 = floatingElementRef.current) === null || _floatingElementRef$c4 === void 0 ? void 0 : _floatingElementRef$c4.clientHeight) !== null && _floatingElementRef$c3 !== void 0 ? _floatingElementRef$c3 : 0) && updateElementHeight()) return prev;
|
|
64
|
+
if (((_anchorElementRef$cur = (_anchorElementRef$cur2 = anchorElementRef.current) === null || _anchorElementRef$cur2 === void 0 ? void 0 : _anchorElementRef$cur2.getBoundingClientRect().top) !== null && _anchorElementRef$cur !== void 0 ? _anchorElementRef$cur : 0) > ((_floatingElementRef$c3 = (_floatingElementRef$c4 = floatingElementRef.current) === null || _floatingElementRef$c4 === void 0 ? void 0 : _floatingElementRef$c4.clientHeight) !== null && _floatingElementRef$c3 !== void 0 ? _floatingElementRef$c3 : 0) && updateElementHeight(prevHeight)) return prev;
|
|
68
65
|
}
|
|
69
66
|
if (prev && prev.anchorSide === newPosition.anchorSide) {
|
|
70
67
|
var _savedOnPositionChang;
|
|
71
68
|
(_savedOnPositionChang = savedOnPositionChange.current) === null || _savedOnPositionChang === void 0 || _savedOnPositionChang.call(savedOnPositionChange, newPosition);
|
|
72
69
|
}
|
|
70
|
+
if (prev && prev.top === newPosition.top && prev.left === newPosition.left && prev.anchorSide === newPosition.anchorSide && prev.anchorAlign === newPosition.anchorAlign) return prev;
|
|
73
71
|
return newPosition;
|
|
74
72
|
});
|
|
75
73
|
} else {
|
|
@@ -77,11 +75,21 @@ function useAnchoredPosition(settings, dependencies = []) {
|
|
|
77
75
|
setPosition(void 0);
|
|
78
76
|
(_savedOnPositionChang2 = savedOnPositionChange.current) === null || _savedOnPositionChang2 === void 0 || _savedOnPositionChang2.call(savedOnPositionChange, void 0);
|
|
79
77
|
}
|
|
80
|
-
|
|
78
|
+
prevHeightRef.current = floatingElementRef.current ? {
|
|
79
|
+
element: floatingElementRef.current,
|
|
80
|
+
height: floatingElementRef.current.clientHeight
|
|
81
|
+
} : void 0;
|
|
81
82
|
}, [
|
|
82
83
|
floatingElementRef,
|
|
83
84
|
anchorElementRef,
|
|
84
85
|
enabled,
|
|
86
|
+
settings === null || settings === void 0 ? void 0 : settings.side,
|
|
87
|
+
settings === null || settings === void 0 ? void 0 : settings.align,
|
|
88
|
+
settings === null || settings === void 0 ? void 0 : settings.anchorOffset,
|
|
89
|
+
settings === null || settings === void 0 ? void 0 : settings.alignmentOffset,
|
|
90
|
+
settings === null || settings === void 0 ? void 0 : settings.allowOutOfBounds,
|
|
91
|
+
settings === null || settings === void 0 ? void 0 : settings.displayInViewport,
|
|
92
|
+
settings === null || settings === void 0 ? void 0 : settings.pinPosition,
|
|
85
93
|
...dependencies
|
|
86
94
|
]);
|
|
87
95
|
useIsomorphicLayoutEffect(() => {
|
|
@@ -105,6 +113,11 @@ function useAnchoredPosition(settings, dependencies = []) {
|
|
|
105
113
|
}
|
|
106
114
|
}, [updatePosition]);
|
|
107
115
|
useResizeObserver(updatePosition, void 0, [], enabled);
|
|
116
|
+
React.useEffect(() => {
|
|
117
|
+
if (!enabled) return;
|
|
118
|
+
window.addEventListener("resize", updatePosition);
|
|
119
|
+
return () => window.removeEventListener("resize", updatePosition);
|
|
120
|
+
}, [enabled, updatePosition]);
|
|
108
121
|
useResizeObserver(updatePosition, floatingElementRef, [], enabled);
|
|
109
122
|
const scrollAncestorsCacheRef = React.useRef({
|
|
110
123
|
anchor: null,
|
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-20261112223856",
|
|
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",
|
|
@@ -94,16 +94,16 @@
|
|
|
94
94
|
},
|
|
95
95
|
"devDependencies": {
|
|
96
96
|
"@actions/core": "1.11.1",
|
|
97
|
-
"@babel/cli": "8.0
|
|
98
|
-
"@babel/core": "8.0
|
|
99
|
-
"@babel/generator": "8.0
|
|
100
|
-
"@babel/parser": "8.0
|
|
97
|
+
"@babel/cli": "8.1.0",
|
|
98
|
+
"@babel/core": "8.1.0",
|
|
99
|
+
"@babel/generator": "8.1.0",
|
|
100
|
+
"@babel/parser": "8.1.0",
|
|
101
101
|
"@babel/plugin-transform-nullish-coalescing-operator": "8.0.1",
|
|
102
102
|
"@babel/plugin-transform-optional-chaining": "8.0.5",
|
|
103
103
|
"@babel/plugin-transform-modules-commonjs": "8.0.1",
|
|
104
104
|
"@babel/preset-react": "8.0.1",
|
|
105
105
|
"@babel/preset-typescript": "8.0.7",
|
|
106
|
-
"@babel/types": "8.0
|
|
106
|
+
"@babel/types": "8.1.0",
|
|
107
107
|
"@figma/code-connect": "1.3.2",
|
|
108
108
|
"@primer/css": "^21.5.1",
|
|
109
109
|
"@primer/doc-gen": "^0.0.1",
|
|
@@ -169,7 +169,7 @@
|
|
|
169
169
|
"rolldown-plugin-dts": "^0.26.0",
|
|
170
170
|
"rolldown-plugin-import-css": "^0.0.0",
|
|
171
171
|
"rolldown-plugin-preserve-directives": "^0.0.0",
|
|
172
|
-
"storybook": "10.6.
|
|
172
|
+
"storybook": "10.6.5",
|
|
173
173
|
"terser": "5.36.0",
|
|
174
174
|
"ts-toolbelt": "9.6.0",
|
|
175
175
|
"tsx": "4.20.3",
|