@sanity/ui 2.6.5 → 2.6.7-canary.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/dist/index.d.mts +42 -6
- package/dist/index.d.ts +42 -6
- package/dist/index.esm.js +80 -147
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +79 -146
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +80 -147
- package/dist/index.mjs.map +1 -1
- package/package.json +26 -34
- package/src/core/components/breadcrumbs/breadcrumbs.tsx +15 -6
- package/src/core/components/dialog/dialog.tsx +12 -21
- package/src/core/components/menu/menu.tsx +11 -18
- package/src/core/components/menu/menuButton.tsx +1 -1
- package/src/core/components/menu/menuContext.ts +1 -1
- package/src/core/components/menu/useMenuController.ts +11 -17
- package/src/core/components/toast/styles.ts +2 -1
- package/src/core/components/toast/useToast.ts +1 -0
- package/src/core/components/tree/tree.tsx +1 -0
- package/src/core/components/tree/treeItem.tsx +1 -0
- package/src/core/helpers/focus.ts +1 -0
- package/src/core/helpers/scroll.ts +1 -0
- package/src/core/hooks/index.ts +3 -2
- package/src/core/hooks/useClickOutside.ts +38 -72
- package/src/core/hooks/useElementSize.ts +1 -0
- package/src/core/hooks/useMatchMedia.ts +46 -0
- package/src/core/hooks/useMediaIndex/useMediaIndex.ts +2 -10
- package/src/core/hooks/usePrefersDark.ts +10 -55
- package/src/core/hooks/usePrefersReducedMotion.ts +10 -56
- package/src/core/primitives/popover/__workshop__/AlignedStory.tsx +9 -7
- package/src/core/primitives/tooltip/__workshop__/customPortal.tsx +8 -6
- package/src/core/primitives/tooltip/tooltip.tsx +7 -5
- package/src/core/primitives/tooltip/tooltipDelayGroup/tooltipDelayGroupProvider.tsx +1 -0
- package/src/core/utils/layer/layerProvider.tsx +1 -0
- package/src/core/utils/portal/__workshop__/named.tsx +10 -8
- package/src/core/utils/portal/portalProvider.tsx +2 -3
- package/src/core/hooks/_internal/index.ts +0 -1
- package/src/core/hooks/_internal/useUnique.ts +0 -34
package/dist/index.js
CHANGED
|
@@ -126,45 +126,26 @@ function useArrayProp(val, defaultVal) {
|
|
|
126
126
|
[__perf_hash__]
|
|
127
127
|
);
|
|
128
128
|
}
|
|
129
|
-
function _getElements(element, elementsArg) {
|
|
130
|
-
const ret = [element];
|
|
131
|
-
for (const el of elementsArg)
|
|
132
|
-
Array.isArray(el) ? ret.push(...el) : ret.push(el);
|
|
133
|
-
return ret.filter(Boolean);
|
|
134
|
-
}
|
|
135
129
|
function useClickOutside(listener, elementsArg = EMPTY_ARRAY, boundaryElement) {
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (prevElements.length !== nextElements.length) {
|
|
140
|
-
setElements(nextElements), elementsRef.current = nextElements;
|
|
130
|
+
const eventHandler = useEffectEvent.useEffectEvent((evt) => {
|
|
131
|
+
const target = evt.target;
|
|
132
|
+
if (!(target instanceof Node) || boundaryElement && !boundaryElement.contains(target))
|
|
141
133
|
return;
|
|
142
|
-
|
|
143
|
-
for (const el of
|
|
144
|
-
if (
|
|
145
|
-
setElements(nextElements), elementsRef.current = nextElements;
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
for (const el of nextElements)
|
|
149
|
-
if (!prevElements.includes(el)) {
|
|
150
|
-
setElements(nextElements), elementsRef.current = nextElements;
|
|
134
|
+
const elements = (Array.isArray(elementsArg) ? elementsArg : elementsArg()).flat();
|
|
135
|
+
for (const el of elements)
|
|
136
|
+
if (el && (target === el || el.contains(target)))
|
|
151
137
|
return;
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
};
|
|
164
|
-
return window.addEventListener("mousedown", handleWindowMouseDown), () => {
|
|
165
|
-
window.removeEventListener("mousedown", handleWindowMouseDown);
|
|
166
|
-
};
|
|
167
|
-
}, [boundaryElement, listener, elements]), setElement;
|
|
138
|
+
listener(evt);
|
|
139
|
+
});
|
|
140
|
+
react.useEffect(() => (document.addEventListener("mousedown", eventHandler), document.addEventListener("touchstart", eventHandler), () => {
|
|
141
|
+
document.removeEventListener("mousedown", eventHandler), document.removeEventListener("touchstart", eventHandler);
|
|
142
|
+
}), [eventHandler]);
|
|
143
|
+
}
|
|
144
|
+
function useCustomValidity(ref, customValidity) {
|
|
145
|
+
react.useEffect(() => {
|
|
146
|
+
var _a;
|
|
147
|
+
(_a = ref.current) == null || _a.setCustomValidity(customValidity || "");
|
|
148
|
+
}, [customValidity, ref]);
|
|
168
149
|
}
|
|
169
150
|
var resizeObservers = [], hasActiveObservations = function() {
|
|
170
151
|
return resizeObservers.some(function(ro) {
|
|
@@ -499,9 +480,27 @@ function useElementRect(element) {
|
|
|
499
480
|
const elementSize = useElementSize(element);
|
|
500
481
|
return (elementSize == null ? void 0 : elementSize._contentRect) || null;
|
|
501
482
|
}
|
|
483
|
+
function useForwardedRef(ref) {
|
|
484
|
+
const innerRef = react.useRef(null);
|
|
485
|
+
return react.useImperativeHandle(ref, () => innerRef.current), innerRef;
|
|
486
|
+
}
|
|
502
487
|
function useGlobalKeyDown(onKeyDown) {
|
|
503
488
|
return react.useEffect(() => (addEventListener("keydown", onKeyDown), () => removeEventListener("keydown", onKeyDown)), [onKeyDown]);
|
|
504
489
|
}
|
|
490
|
+
function useMatchMedia(mediaQueryString, getServerSnapshot2) {
|
|
491
|
+
const { subscribe: subscribe2, getSnapshot } = react.useMemo(() => {
|
|
492
|
+
let MEDIA_QUERY_CACHE;
|
|
493
|
+
const getMatchMedia = () => (MEDIA_QUERY_CACHE || (MEDIA_QUERY_CACHE = window.matchMedia(mediaQueryString)), MEDIA_QUERY_CACHE);
|
|
494
|
+
return {
|
|
495
|
+
subscribe: (onStoreChange) => {
|
|
496
|
+
const matchMedia = getMatchMedia();
|
|
497
|
+
return matchMedia.addEventListener("change", onStoreChange), () => matchMedia.removeEventListener("change", onStoreChange);
|
|
498
|
+
},
|
|
499
|
+
getSnapshot: () => getMatchMedia().matches
|
|
500
|
+
};
|
|
501
|
+
}, [mediaQueryString]);
|
|
502
|
+
return react.useDebugValue(mediaQueryString), react.useSyncExternalStore(subscribe2, getSnapshot, getServerSnapshot2);
|
|
503
|
+
}
|
|
505
504
|
function getGlobalScope() {
|
|
506
505
|
if (typeof globalThis < "u") return globalThis;
|
|
507
506
|
if (typeof window < "u") return window;
|
|
@@ -544,7 +543,6 @@ function useTheme() {
|
|
|
544
543
|
function useTheme_v2() {
|
|
545
544
|
return theme.getTheme_v2(styledComponents.useTheme());
|
|
546
545
|
}
|
|
547
|
-
const MEDIA_STORE_CACHE = /* @__PURE__ */ new WeakMap();
|
|
548
546
|
function _getMediaQuery(media, index) {
|
|
549
547
|
return index === 0 ? `screen and (max-width: ${media[index] - 1}px)` : index === media.length ? `screen and (min-width: ${media[index - 1]}px)` : `screen and (min-width: ${media[index - 1]}px) and (max-width: ${media[index] - 1}px)`;
|
|
550
548
|
}
|
|
@@ -579,57 +577,18 @@ function _createMediaStore(media) {
|
|
|
579
577
|
};
|
|
580
578
|
} };
|
|
581
579
|
}
|
|
582
|
-
function getServerSnapshot
|
|
580
|
+
function getServerSnapshot() {
|
|
583
581
|
return 0;
|
|
584
582
|
}
|
|
585
583
|
function useMediaIndex() {
|
|
586
|
-
const { media } = useTheme_v2();
|
|
587
|
-
|
|
588
|
-
return store || (store = _createMediaStore(media), MEDIA_STORE_CACHE.set(media, store)), react.useSyncExternalStore(store.subscribe, store.getSnapshot, getServerSnapshot$2);
|
|
584
|
+
const { media } = useTheme_v2(), store = react.useMemo(() => _createMediaStore(media), [media]);
|
|
585
|
+
return react.useSyncExternalStore(store.subscribe, store.getSnapshot, getServerSnapshot);
|
|
589
586
|
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
return MEDIA_QUERY_CACHE$1 || (MEDIA_QUERY_CACHE$1 = window.matchMedia("(prefers-color-scheme: dark)")), MEDIA_QUERY_CACHE$1;
|
|
587
|
+
function usePrefersDark(getServerSnapshot2 = () => !1) {
|
|
588
|
+
return useMatchMedia("(prefers-color-scheme: dark)", getServerSnapshot2);
|
|
593
589
|
}
|
|
594
|
-
function
|
|
595
|
-
|
|
596
|
-
return matchMedia.addEventListener("change", onStoreChange), () => matchMedia.removeEventListener("change", onStoreChange);
|
|
597
|
-
}
|
|
598
|
-
function getSnapshot$1() {
|
|
599
|
-
return getMatchMedia$1().matches;
|
|
600
|
-
}
|
|
601
|
-
function getServerSnapshot$1() {
|
|
602
|
-
return !1;
|
|
603
|
-
}
|
|
604
|
-
function usePrefersDark() {
|
|
605
|
-
return react.useSyncExternalStore(subscribe$2, getSnapshot$1, getServerSnapshot$1);
|
|
606
|
-
}
|
|
607
|
-
let MEDIA_QUERY_CACHE;
|
|
608
|
-
function getMatchMedia() {
|
|
609
|
-
return MEDIA_QUERY_CACHE || (MEDIA_QUERY_CACHE = window.matchMedia("(prefers-reduced-motion: reduce)")), MEDIA_QUERY_CACHE;
|
|
610
|
-
}
|
|
611
|
-
function subscribe$1(onStoreChange) {
|
|
612
|
-
const matchMedia = getMatchMedia();
|
|
613
|
-
return matchMedia.addEventListener("change", onStoreChange), () => matchMedia.removeEventListener("change", onStoreChange);
|
|
614
|
-
}
|
|
615
|
-
function getSnapshot() {
|
|
616
|
-
return getMatchMedia().matches;
|
|
617
|
-
}
|
|
618
|
-
function getServerSnapshot() {
|
|
619
|
-
return !1;
|
|
620
|
-
}
|
|
621
|
-
function usePrefersReducedMotion() {
|
|
622
|
-
return react.useSyncExternalStore(subscribe$1, getSnapshot, getServerSnapshot);
|
|
623
|
-
}
|
|
624
|
-
function useForwardedRef(ref) {
|
|
625
|
-
const innerRef = react.useRef(null);
|
|
626
|
-
return react.useImperativeHandle(ref, () => innerRef.current), innerRef;
|
|
627
|
-
}
|
|
628
|
-
function useCustomValidity(ref, customValidity) {
|
|
629
|
-
react.useEffect(() => {
|
|
630
|
-
var _a;
|
|
631
|
-
(_a = ref.current) == null || _a.setCustomValidity(customValidity || "");
|
|
632
|
-
}, [customValidity, ref]);
|
|
590
|
+
function usePrefersReducedMotion(getServerSnapshot2 = () => !1) {
|
|
591
|
+
return useMatchMedia("(prefers-reduced-motion: reduce)", getServerSnapshot2);
|
|
633
592
|
}
|
|
634
593
|
function responsiveBorderStyle() {
|
|
635
594
|
return [border, borderTop, borderRight, borderBottom, borderLeft];
|
|
@@ -3055,16 +3014,6 @@ function Portal(props) {
|
|
|
3055
3014
|
const { children, __unstable_name: name } = props, portal = usePortal(), portalElement = (name ? portal.elements && portal.elements[name] : portal.element) || ((_a = portal.elements) == null ? void 0 : _a.default);
|
|
3056
3015
|
return portalElement ? reactDom.createPortal(children, portalElement) : null;
|
|
3057
3016
|
}
|
|
3058
|
-
function useUnique(value) {
|
|
3059
|
-
const valueRef = react.useRef(value);
|
|
3060
|
-
return _isEqual(valueRef.current, value) || (valueRef.current = value), valueRef.current;
|
|
3061
|
-
}
|
|
3062
|
-
function _isEqual(objA, objB) {
|
|
3063
|
-
if (!objA || !objB)
|
|
3064
|
-
return objA === objB;
|
|
3065
|
-
const keysA = Object.keys(objA), keysB = Object.keys(objB);
|
|
3066
|
-
return keysA.length !== keysB.length ? !1 : keysA.every((key2) => objA[key2] === objB[key2]);
|
|
3067
|
-
}
|
|
3068
3017
|
function useMounted() {
|
|
3069
3018
|
return react.useSyncExternalStore(
|
|
3070
3019
|
subscribe,
|
|
@@ -3075,7 +3024,7 @@ function useMounted() {
|
|
|
3075
3024
|
const subscribe = () => () => {
|
|
3076
3025
|
};
|
|
3077
3026
|
function PortalProvider(props) {
|
|
3078
|
-
const { boundaryElement, children, element, __unstable_elements:
|
|
3027
|
+
const { boundaryElement, children, element, __unstable_elements: elements } = props, mounted = useMounted(), value = react.useMemo(() => ({
|
|
3079
3028
|
version: 0,
|
|
3080
3029
|
boundaryElement: boundaryElement || null,
|
|
3081
3030
|
element: element || mounted ? document.body : null,
|
|
@@ -4430,7 +4379,7 @@ const Root$a = styledComponents.styled(Layer)`
|
|
|
4430
4379
|
},
|
|
4431
4380
|
[childProp == null ? void 0 : childProp.props, handleIsOpenChange]
|
|
4432
4381
|
);
|
|
4433
|
-
react.useEffect(() => {
|
|
4382
|
+
useCloseOnMouseLeave({ handleIsOpenChange, referenceElement, showTooltip }), react.useEffect(() => {
|
|
4434
4383
|
disabled && showTooltip && handleIsOpenChange(!1);
|
|
4435
4384
|
}, [disabled, handleIsOpenChange, showTooltip]), react.useEffect(() => {
|
|
4436
4385
|
!content && showTooltip && handleIsOpenChange(!1);
|
|
@@ -4442,7 +4391,7 @@ const Root$a = styledComponents.styled(Layer)`
|
|
|
4442
4391
|
return window.addEventListener("keydown", handleWindowKeyDown), () => {
|
|
4443
4392
|
window.removeEventListener("keydown", handleWindowKeyDown);
|
|
4444
4393
|
};
|
|
4445
|
-
}, [handleIsOpenChange, showTooltip]),
|
|
4394
|
+
}, [handleIsOpenChange, showTooltip]), react.useLayoutEffect(() => {
|
|
4446
4395
|
const availableWidths = [
|
|
4447
4396
|
...boundaryElement ? [boundaryElement.offsetWidth] : [],
|
|
4448
4397
|
(portalElement == null ? void 0 : portalElement.offsetWidth) || document.body.offsetWidth
|
|
@@ -4540,13 +4489,13 @@ function useCloseOnMouseLeave({
|
|
|
4540
4489
|
referenceElement,
|
|
4541
4490
|
showTooltip
|
|
4542
4491
|
}) {
|
|
4543
|
-
const onMouseMove = useEffectEvent.useEffectEvent((target) => {
|
|
4544
|
-
referenceElement && (referenceElement === target || target instanceof Node && referenceElement.contains(target) || handleIsOpenChange(!1));
|
|
4492
|
+
const onMouseMove = useEffectEvent.useEffectEvent((target, teardown) => {
|
|
4493
|
+
referenceElement && (referenceElement === target || target instanceof Node && referenceElement.contains(target) || (handleIsOpenChange(!1), teardown()));
|
|
4545
4494
|
});
|
|
4546
4495
|
react.useEffect(() => {
|
|
4547
4496
|
if (!showTooltip) return;
|
|
4548
4497
|
const handleMouseMove = (event) => {
|
|
4549
|
-
onMouseMove(event.target);
|
|
4498
|
+
onMouseMove(event.target, () => window.removeEventListener("mousemove", handleMouseMove));
|
|
4550
4499
|
};
|
|
4551
4500
|
return window.addEventListener("mousemove", handleMouseMove), () => window.removeEventListener("mousemove", handleMouseMove);
|
|
4552
4501
|
}, [onMouseMove, showTooltip]);
|
|
@@ -4962,8 +4911,8 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
|
|
|
4962
4911
|
appearance: none;
|
|
4963
4912
|
margin: -4px;
|
|
4964
4913
|
`, Breadcrumbs = react.forwardRef(function(props, ref) {
|
|
4965
|
-
const { children, maxLength, separator, space: spaceRaw = 2, ...restProps } = props, space = useArrayProp(spaceRaw), [open, setOpen] = react.useState(!1),
|
|
4966
|
-
useClickOutside(collapse, [
|
|
4914
|
+
const { children, maxLength, separator, space: spaceRaw = 2, ...restProps } = props, space = useArrayProp(spaceRaw), [open, setOpen] = react.useState(!1), expandElementRef = react.useRef(null), popoverElementRef = react.useRef(null), collapse = react.useCallback(() => setOpen(!1), []), expand = react.useCallback(() => setOpen(!0), []);
|
|
4915
|
+
useClickOutside(collapse, () => [expandElementRef.current, popoverElementRef.current]);
|
|
4967
4916
|
const rawItems = react.useMemo(() => react.Children.toArray(children).filter(react.isValidElement), [children]), items = react.useMemo(() => {
|
|
4968
4917
|
const len = rawItems.length;
|
|
4969
4918
|
if (maxLength && len > maxLength) {
|
|
@@ -4978,7 +4927,7 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
|
|
|
4978
4927
|
open,
|
|
4979
4928
|
placement: "top",
|
|
4980
4929
|
portal: !0,
|
|
4981
|
-
ref:
|
|
4930
|
+
ref: popoverElementRef,
|
|
4982
4931
|
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4983
4932
|
ExpandButton,
|
|
4984
4933
|
{
|
|
@@ -4986,7 +4935,7 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
|
|
|
4986
4935
|
mode: "bleed",
|
|
4987
4936
|
onClick: open ? collapse : expand,
|
|
4988
4937
|
padding: 1,
|
|
4989
|
-
ref:
|
|
4938
|
+
ref: expandElementRef,
|
|
4990
4939
|
selected: open,
|
|
4991
4940
|
text: "\u2026"
|
|
4992
4941
|
}
|
|
@@ -5111,8 +5060,8 @@ const Root$7 = styledComponents.styled(Layer)(responsivePaddingStyle, dialogStyl
|
|
|
5111
5060
|
scheme,
|
|
5112
5061
|
shadow: shadowProp,
|
|
5113
5062
|
width: widthProp
|
|
5114
|
-
} = props, portal = usePortal(), portalElement = portalProp ? ((_a = portal.elements) == null ? void 0 : _a[portalProp]) || null : portal.element, boundaryElement = useBoundaryElement().element, radius = useArrayProp(radiusProp), shadow = useArrayProp(shadowProp), width = useArrayProp(widthProp), ref = react.useRef(null),
|
|
5115
|
-
react.useImperativeHandle(forwardedRef, () => ref.current), react.useImperativeHandle(
|
|
5063
|
+
} = props, portal = usePortal(), portalElement = portalProp ? ((_a = portal.elements) == null ? void 0 : _a[portalProp]) || null : portal.element, boundaryElement = useBoundaryElement().element, radius = useArrayProp(radiusProp), shadow = useArrayProp(shadowProp), width = useArrayProp(widthProp), ref = react.useRef(null), contentRef = react.useRef(null), layer = useLayer(), { isTopLayer } = layer, labelId = `${id}_label`, showCloseButton = !!onClose && hideCloseButton === !1, showHeader = !!header || showCloseButton;
|
|
5064
|
+
return react.useImperativeHandle(forwardedRef, () => ref.current), react.useImperativeHandle(
|
|
5116
5065
|
forwardedContentRef,
|
|
5117
5066
|
() => contentRef.current
|
|
5118
5067
|
), react.useEffect(() => {
|
|
@@ -5127,20 +5076,13 @@ const Root$7 = styledComponents.styled(Layer)(responsivePaddingStyle, dialogStyl
|
|
|
5127
5076
|
[boundaryElement, isTopLayer, onClose, portalElement]
|
|
5128
5077
|
)
|
|
5129
5078
|
), useClickOutside(
|
|
5130
|
-
|
|
5131
|
-
(
|
|
5132
|
-
|
|
5133
|
-
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
),
|
|
5138
|
-
[rootElement]
|
|
5139
|
-
);
|
|
5140
|
-
const setRef = react.useCallback((el) => {
|
|
5141
|
-
setRootElement(el), ref.current = el;
|
|
5142
|
-
}, []);
|
|
5143
|
-
return /* @__PURE__ */ jsxRuntime.jsx(DialogContainer, { "data-ui": "DialogCard", width, children: /* @__PURE__ */ jsxRuntime.jsx(DialogCardRoot, { radius, ref: setRef, scheme, shadow, children: /* @__PURE__ */ jsxRuntime.jsxs(DialogLayout, { direction: "column", children: [
|
|
5079
|
+
(event) => {
|
|
5080
|
+
if (!isTopLayer || !onClickOutside) return;
|
|
5081
|
+
const target = event.target;
|
|
5082
|
+
target && !isTargetWithinScope(boundaryElement, portalElement, target) || onClickOutside();
|
|
5083
|
+
},
|
|
5084
|
+
() => [ref.current]
|
|
5085
|
+
), /* @__PURE__ */ jsxRuntime.jsx(DialogContainer, { "data-ui": "DialogCard", width, children: /* @__PURE__ */ jsxRuntime.jsx(DialogCardRoot, { radius, ref, scheme, shadow, children: /* @__PURE__ */ jsxRuntime.jsxs(DialogLayout, { direction: "column", children: [
|
|
5144
5086
|
showHeader && /* @__PURE__ */ jsxRuntime.jsx(DialogHeader, { children: /* @__PURE__ */ jsxRuntime.jsxs(Flex, { align: "center", padding: 3, children: [
|
|
5145
5087
|
/* @__PURE__ */ jsxRuntime.jsx(Box, { flex: 1, padding: 2, children: header && /* @__PURE__ */ jsxRuntime.jsx(Text, { id: labelId, size: 1, weight: "semibold", children: header }) }),
|
|
5146
5088
|
showCloseButton && /* @__PURE__ */ jsxRuntime.jsx(Box, { flex: "none", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -5318,13 +5260,13 @@ function _sortElements(rootElement, elements) {
|
|
|
5318
5260
|
elements.sort(_sort);
|
|
5319
5261
|
}
|
|
5320
5262
|
function useMenuController(props) {
|
|
5321
|
-
const { onKeyDown, originElement, shouldFocus } = props, elementsRef = react.useRef([]), [
|
|
5263
|
+
const { onKeyDown, originElement, shouldFocus, rootElementRef } = props, elementsRef = react.useRef([]), [activeIndex, _setActiveIndex] = react.useState(-1), activeIndexRef = react.useRef(activeIndex), activeElement = react.useMemo(() => elementsRef.current[activeIndex] || null, [activeIndex]), mounted = !!rootElementRef.current, setActiveIndex = react.useCallback((nextActiveIndex) => {
|
|
5322
5264
|
_setActiveIndex(nextActiveIndex), activeIndexRef.current = nextActiveIndex;
|
|
5323
5265
|
}, []), mount = react.useCallback(
|
|
5324
5266
|
(element, selected) => {
|
|
5325
5267
|
if (!element) return () => {
|
|
5326
5268
|
};
|
|
5327
|
-
if (elementsRef.current.indexOf(element) === -1 && (elementsRef.current.push(element), _sortElements(
|
|
5269
|
+
if (elementsRef.current.indexOf(element) === -1 && (elementsRef.current.push(element), _sortElements(rootElementRef.current, elementsRef.current)), selected) {
|
|
5328
5270
|
const selectedIndex = elementsRef.current.indexOf(element);
|
|
5329
5271
|
setActiveIndex(selectedIndex);
|
|
5330
5272
|
}
|
|
@@ -5333,7 +5275,7 @@ function useMenuController(props) {
|
|
|
5333
5275
|
idx > -1 && elementsRef.current.splice(idx, 1);
|
|
5334
5276
|
};
|
|
5335
5277
|
},
|
|
5336
|
-
[
|
|
5278
|
+
[rootElementRef, setActiveIndex]
|
|
5337
5279
|
), handleKeyDown = react.useCallback(
|
|
5338
5280
|
(event) => {
|
|
5339
5281
|
if (event.key === "Tab") {
|
|
@@ -5388,13 +5330,13 @@ function useMenuController(props) {
|
|
|
5388
5330
|
},
|
|
5389
5331
|
[setActiveIndex]
|
|
5390
5332
|
), handleItemMouseLeave = react.useCallback(() => {
|
|
5391
|
-
|
|
5392
|
-
|
|
5333
|
+
var _a;
|
|
5334
|
+
setActiveIndex(-2), (_a = rootElementRef.current) == null || _a.focus();
|
|
5335
|
+
}, [rootElementRef, setActiveIndex]);
|
|
5393
5336
|
return react.useEffect(() => {
|
|
5394
5337
|
if (!mounted) return;
|
|
5395
5338
|
const rafId = window.requestAnimationFrame(() => {
|
|
5396
|
-
|
|
5397
|
-
if (_activeIndex === -1) {
|
|
5339
|
+
if (activeIndex === -1) {
|
|
5398
5340
|
if (shouldFocus === "first") {
|
|
5399
5341
|
const el = _getFocusableElements(elementsRef.current)[0];
|
|
5400
5342
|
if (el) {
|
|
@@ -5411,7 +5353,7 @@ function useMenuController(props) {
|
|
|
5411
5353
|
}
|
|
5412
5354
|
return;
|
|
5413
5355
|
}
|
|
5414
|
-
const element = elementsRef.current[
|
|
5356
|
+
const element = elementsRef.current[activeIndex] || null;
|
|
5415
5357
|
element == null || element.focus();
|
|
5416
5358
|
});
|
|
5417
5359
|
return () => {
|
|
@@ -5423,9 +5365,7 @@ function useMenuController(props) {
|
|
|
5423
5365
|
handleItemMouseEnter,
|
|
5424
5366
|
handleItemMouseLeave,
|
|
5425
5367
|
handleKeyDown,
|
|
5426
|
-
mount
|
|
5427
|
-
rootElement,
|
|
5428
|
-
setRootElement
|
|
5368
|
+
mount
|
|
5429
5369
|
};
|
|
5430
5370
|
}
|
|
5431
5371
|
const Root$5 = styledComponents.styled(Box)`
|
|
@@ -5457,23 +5397,18 @@ const Root$5 = styledComponents.styled(Box)`
|
|
|
5457
5397
|
handleItemMouseEnter,
|
|
5458
5398
|
handleItemMouseLeave,
|
|
5459
5399
|
handleKeyDown,
|
|
5460
|
-
mount
|
|
5461
|
-
|
|
5462
|
-
setRootElement
|
|
5463
|
-
} = useMenuController({ onKeyDown, originElement, shouldFocus }), handleRefChange = react.useCallback(
|
|
5400
|
+
mount
|
|
5401
|
+
} = useMenuController({ onKeyDown, originElement, shouldFocus, rootElementRef: ref }), handleRefChange = react.useCallback(
|
|
5464
5402
|
(el) => {
|
|
5465
|
-
|
|
5403
|
+
ref.current = el, ref.current && registerElement && registerElement(ref.current);
|
|
5466
5404
|
},
|
|
5467
|
-
[
|
|
5405
|
+
[registerElement]
|
|
5468
5406
|
);
|
|
5469
5407
|
react.useEffect(() => {
|
|
5470
5408
|
onItemSelect && onItemSelect(activeIndex);
|
|
5471
5409
|
}, [activeIndex, onItemSelect]), useClickOutside(
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
[isTopLayer, onClickOutside]
|
|
5475
|
-
),
|
|
5476
|
-
[rootElement]
|
|
5410
|
+
(event) => isTopLayer && onClickOutside && onClickOutside(event),
|
|
5411
|
+
() => [ref.current]
|
|
5477
5412
|
), useGlobalKeyDown(
|
|
5478
5413
|
react.useCallback(
|
|
5479
5414
|
(event) => {
|
|
@@ -5481,10 +5416,7 @@ const Root$5 = styledComponents.styled(Box)`
|
|
|
5481
5416
|
},
|
|
5482
5417
|
[isTopLayer, onEscape]
|
|
5483
5418
|
)
|
|
5484
|
-
)
|
|
5485
|
-
if (!(!rootElement || !registerElement))
|
|
5486
|
-
return registerElement(rootElement);
|
|
5487
|
-
}, [registerElement, rootElement]);
|
|
5419
|
+
);
|
|
5488
5420
|
const value = react.useMemo(
|
|
5489
5421
|
() => ({
|
|
5490
5422
|
version: 0,
|
|
@@ -6160,7 +6092,7 @@ const CustomInline = styledComponents.styled(Inline)`
|
|
|
6160
6092
|
}
|
|
6161
6093
|
100% {
|
|
6162
6094
|
width: 100%;
|
|
6163
|
-
}
|
|
6095
|
+
}
|
|
6164
6096
|
`, LOADING_BAR_HEIGHT = 2;
|
|
6165
6097
|
function rootStyles(props) {
|
|
6166
6098
|
const { color } = getTheme_v2.getTheme_v2(props.theme), loadingBarColor = color.button.default[props.tone].enabled.bg;
|
|
@@ -6857,6 +6789,7 @@ exports.useElementSize = useElementSize;
|
|
|
6857
6789
|
exports.useForwardedRef = useForwardedRef;
|
|
6858
6790
|
exports.useGlobalKeyDown = useGlobalKeyDown;
|
|
6859
6791
|
exports.useLayer = useLayer;
|
|
6792
|
+
exports.useMatchMedia = useMatchMedia;
|
|
6860
6793
|
exports.useMediaIndex = useMediaIndex;
|
|
6861
6794
|
exports.usePortal = usePortal;
|
|
6862
6795
|
exports.usePrefersDark = usePrefersDark;
|