@sanity/ui 2.6.4-canary.0 → 2.6.4-canary.2
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 +51 -15
- package/dist/index.d.ts +51 -15
- package/dist/index.esm.js +103 -167
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +102 -167
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +103 -167
- package/dist/index.mjs.map +1 -1
- package/dist/theme.d.mts +14 -14
- package/dist/theme.d.ts +14 -14
- package/dist/theme.esm.js.map +1 -1
- package/dist/theme.js.map +1 -1
- package/dist/theme.mjs.map +1 -1
- package/package.json +28 -27
- package/src/core/__workshop__/constants.ts +36 -36
- package/src/core/components/autocomplete/autocomplete.tsx +1 -1
- package/src/core/components/breadcrumbs/breadcrumbs.tsx +15 -6
- package/src/core/components/dialog/dialog.tsx +12 -21
- package/src/core/components/dialog/styles.ts +8 -8
- package/src/core/components/menu/menu.tsx +11 -18
- package/src/core/components/menu/menuButton.tsx +11 -11
- package/src/core/components/menu/menuContext.ts +1 -1
- package/src/core/components/menu/useMenuController.ts +11 -18
- package/src/core/components/tab/tab.tsx +8 -8
- package/src/core/components/tab/tabPanel.tsx +1 -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/hooks/index.ts +3 -2
- package/src/core/hooks/useClickOutside.ts +37 -74
- package/src/core/hooks/useMatchMedia.ts +46 -0
- package/src/core/hooks/useMediaIndex/useMediaIndex.ts +2 -11
- package/src/core/hooks/usePrefersDark.ts +10 -58
- package/src/core/hooks/usePrefersReducedMotion.ts +10 -58
- package/src/core/primitives/avatar/styles.ts +42 -42
- package/src/core/primitives/badge/styles.ts +2 -2
- package/src/core/primitives/button/styles.ts +4 -4
- package/src/core/primitives/inline/styles.ts +2 -2
- package/src/core/primitives/popover/__workshop__/AlignedStory.tsx +9 -7
- package/src/core/primitives/popover/constants.ts +4 -4
- package/src/core/primitives/stack/styles.ts +2 -2
- package/src/core/primitives/tooltip/__workshop__/customPortal.tsx +9 -7
- package/src/core/primitives/tooltip/constants.ts +4 -4
- package/src/core/primitives/tooltip/tooltip.tsx +45 -27
- package/src/core/primitives/tooltip/tooltipDelayGroup/tooltipDelayGroupProvider.tsx +1 -0
- package/src/core/styles/font/responsiveFont.ts +8 -8
- package/src/core/theme/__workshop__/debug/story.tsx +11 -11
- 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 +7 -14
- package/src/theme/build/buildColorTheme.test.ts +13 -13
- package/src/theme/config/tokens/color/types.ts +14 -14
- package/src/theme/defaults/colorTokens.ts +36 -36
- package/src/core/hooks/_internal/index.ts +0 -1
- package/src/core/hooks/_internal/useUnique.ts +0 -34
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { buildTheme, createColorTheme as createColorTheme$1, hexToRgb as hexToRgb$1, hslToRgb as hslToRgb$1, multiply as multiply$1, parseColor as parseColor$1, rgbToHex as rgbToHex$1, rgbToHsl as rgbToHsl$1, rgba as rgba$1, screen as screen$1, getTheme_v2, getScopedTheme } from "@sanity/ui/theme";
|
|
2
2
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
3
|
-
import { useMemo, useState, useRef,
|
|
3
|
+
import { useMemo, useEffect, useState, useRef, useImperativeHandle, useDebugValue, useSyncExternalStore, createContext, useContext, forwardRef, useId, useCallback, Children, isValidElement, cloneElement, Component, memo, useReducer, Fragment as Fragment$1, startTransition } from "react";
|
|
4
4
|
import ReactIs, { isValidElementType } from "react-is";
|
|
5
5
|
import { ThemeProvider as ThemeProvider$1, useTheme as useTheme$1, css, styled, keyframes } from "styled-components";
|
|
6
6
|
import { SpinnerIcon, CheckmarkIcon, RemoveIcon, ChevronDownIcon, CloseIcon, ChevronRightIcon, ToggleArrowRightIcon } from "@sanity/icons";
|
|
@@ -8,6 +8,7 @@ import Refractor from "react-refractor";
|
|
|
8
8
|
import { detectOverflow, flip, offset, shift, arrow, hide, useFloating, autoUpdate, size as size$2 } from "@floating-ui/react-dom";
|
|
9
9
|
import { motion, AnimatePresence } from "framer-motion";
|
|
10
10
|
import { createPortal } from "react-dom";
|
|
11
|
+
import { useEffectEvent } from "use-effect-event";
|
|
11
12
|
import { getTheme_v2 as getTheme_v2$1 } from "./_legacy/getTheme_v2.esm.js";
|
|
12
13
|
const createColorTheme = createColorTheme$1, hexToRgb = hexToRgb$1, hslToRgb = hslToRgb$1, multiply = multiply$1, parseColor = parseColor$1, rgbToHex = rgbToHex$1, rgbToHsl = rgbToHsl$1, rgba = rgba$1, screen = screen$1, studioTheme = buildTheme(), EMPTY_ARRAY = [], EMPTY_RECORD = {}, POPOVER_MOTION_CONTENT_OPACITY_PROPERTY = "--motion-content-opacity", POPOVER_MOTION_PROPS = {
|
|
13
14
|
initial: {
|
|
@@ -130,45 +131,26 @@ function useArrayProp(val, defaultVal) {
|
|
|
130
131
|
[__perf_hash__]
|
|
131
132
|
);
|
|
132
133
|
}
|
|
133
|
-
function _getElements(element, elementsArg) {
|
|
134
|
-
const ret = [element];
|
|
135
|
-
for (const el of elementsArg)
|
|
136
|
-
Array.isArray(el) ? ret.push(...el) : ret.push(el);
|
|
137
|
-
return ret.filter(Boolean);
|
|
138
|
-
}
|
|
139
134
|
function useClickOutside(listener, elementsArg = EMPTY_ARRAY, boundaryElement) {
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
if (prevElements.length !== nextElements.length) {
|
|
144
|
-
setElements(nextElements), elementsRef.current = nextElements;
|
|
135
|
+
const eventHandler = useEffectEvent((evt) => {
|
|
136
|
+
const target = evt.target;
|
|
137
|
+
if (!(target instanceof Node) || boundaryElement && !boundaryElement.contains(target))
|
|
145
138
|
return;
|
|
146
|
-
|
|
147
|
-
for (const el of
|
|
148
|
-
if (
|
|
149
|
-
setElements(nextElements), elementsRef.current = nextElements;
|
|
139
|
+
const elements = (Array.isArray(elementsArg) ? elementsArg : elementsArg()).flat();
|
|
140
|
+
for (const el of elements)
|
|
141
|
+
if (el && (target === el || el.contains(target)))
|
|
150
142
|
return;
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
for (const el of elements)
|
|
163
|
-
if (target === el || el.contains(target))
|
|
164
|
-
return;
|
|
165
|
-
listener(evt);
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
return window.addEventListener("mousedown", handleWindowMouseDown), () => {
|
|
169
|
-
window.removeEventListener("mousedown", handleWindowMouseDown);
|
|
170
|
-
};
|
|
171
|
-
}, [boundaryElement, listener, elements]), setElement;
|
|
143
|
+
listener(evt);
|
|
144
|
+
});
|
|
145
|
+
useEffect(() => (document.addEventListener("mousedown", eventHandler), document.addEventListener("touchstart", eventHandler), () => {
|
|
146
|
+
document.removeEventListener("mousedown", eventHandler), document.removeEventListener("touchstart", eventHandler);
|
|
147
|
+
}), [eventHandler]);
|
|
148
|
+
}
|
|
149
|
+
function useCustomValidity(ref, customValidity) {
|
|
150
|
+
useEffect(() => {
|
|
151
|
+
var _a;
|
|
152
|
+
(_a = ref.current) == null || _a.setCustomValidity(customValidity || "");
|
|
153
|
+
}, [customValidity, ref]);
|
|
172
154
|
}
|
|
173
155
|
var resizeObservers = [], hasActiveObservations = function() {
|
|
174
156
|
return resizeObservers.some(function(ro) {
|
|
@@ -503,9 +485,27 @@ function useElementRect(element) {
|
|
|
503
485
|
const elementSize = useElementSize(element);
|
|
504
486
|
return (elementSize == null ? void 0 : elementSize._contentRect) || null;
|
|
505
487
|
}
|
|
488
|
+
function useForwardedRef(ref) {
|
|
489
|
+
const innerRef = useRef(null);
|
|
490
|
+
return useImperativeHandle(ref, () => innerRef.current), innerRef;
|
|
491
|
+
}
|
|
506
492
|
function useGlobalKeyDown(onKeyDown) {
|
|
507
493
|
return useEffect(() => (addEventListener("keydown", onKeyDown), () => removeEventListener("keydown", onKeyDown)), [onKeyDown]);
|
|
508
494
|
}
|
|
495
|
+
function useMatchMedia(mediaQueryString, getServerSnapshot2) {
|
|
496
|
+
const { subscribe: subscribe2, getSnapshot } = useMemo(() => {
|
|
497
|
+
let MEDIA_QUERY_CACHE;
|
|
498
|
+
const getMatchMedia = () => (MEDIA_QUERY_CACHE || (MEDIA_QUERY_CACHE = window.matchMedia(mediaQueryString)), MEDIA_QUERY_CACHE);
|
|
499
|
+
return {
|
|
500
|
+
subscribe: (onStoreChange) => {
|
|
501
|
+
const matchMedia = getMatchMedia();
|
|
502
|
+
return matchMedia.addEventListener("change", onStoreChange), () => matchMedia.removeEventListener("change", onStoreChange);
|
|
503
|
+
},
|
|
504
|
+
getSnapshot: () => getMatchMedia().matches
|
|
505
|
+
};
|
|
506
|
+
}, [mediaQueryString]);
|
|
507
|
+
return useDebugValue(mediaQueryString), useSyncExternalStore(subscribe2, getSnapshot, getServerSnapshot2);
|
|
508
|
+
}
|
|
509
509
|
function getGlobalScope() {
|
|
510
510
|
if (typeof globalThis < "u") return globalThis;
|
|
511
511
|
if (typeof window < "u") return window;
|
|
@@ -548,7 +548,6 @@ function useTheme() {
|
|
|
548
548
|
function useTheme_v2() {
|
|
549
549
|
return getTheme_v2(useTheme$1());
|
|
550
550
|
}
|
|
551
|
-
const MEDIA_STORE_CACHE = /* @__PURE__ */ new WeakMap();
|
|
552
551
|
function _getMediaQuery(media, index) {
|
|
553
552
|
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)`;
|
|
554
553
|
}
|
|
@@ -583,57 +582,18 @@ function _createMediaStore(media) {
|
|
|
583
582
|
};
|
|
584
583
|
} };
|
|
585
584
|
}
|
|
586
|
-
function getServerSnapshot
|
|
585
|
+
function getServerSnapshot() {
|
|
587
586
|
return 0;
|
|
588
587
|
}
|
|
589
588
|
function useMediaIndex() {
|
|
590
|
-
const { media } = useTheme_v2();
|
|
591
|
-
|
|
592
|
-
return store || (store = _createMediaStore(media), MEDIA_STORE_CACHE.set(media, store)), useSyncExternalStore(store.subscribe, store.getSnapshot, getServerSnapshot$2);
|
|
593
|
-
}
|
|
594
|
-
let MEDIA_QUERY_CACHE$1;
|
|
595
|
-
function getMatchMedia$1() {
|
|
596
|
-
return MEDIA_QUERY_CACHE$1 || (MEDIA_QUERY_CACHE$1 = window.matchMedia("(prefers-color-scheme: dark)")), MEDIA_QUERY_CACHE$1;
|
|
597
|
-
}
|
|
598
|
-
function subscribe$2(onStoreChange) {
|
|
599
|
-
const matchMedia = getMatchMedia$1();
|
|
600
|
-
return matchMedia.addEventListener("change", onStoreChange), () => matchMedia.removeEventListener("change", onStoreChange);
|
|
601
|
-
}
|
|
602
|
-
function getSnapshot$1() {
|
|
603
|
-
return getMatchMedia$1().matches;
|
|
604
|
-
}
|
|
605
|
-
function getServerSnapshot$1() {
|
|
606
|
-
return !1;
|
|
607
|
-
}
|
|
608
|
-
function usePrefersDark() {
|
|
609
|
-
return useSyncExternalStore(subscribe$2, getSnapshot$1, getServerSnapshot$1);
|
|
610
|
-
}
|
|
611
|
-
let MEDIA_QUERY_CACHE;
|
|
612
|
-
function getMatchMedia() {
|
|
613
|
-
return MEDIA_QUERY_CACHE || (MEDIA_QUERY_CACHE = window.matchMedia("(prefers-reduced-motion: reduce)")), MEDIA_QUERY_CACHE;
|
|
614
|
-
}
|
|
615
|
-
function subscribe$1(onStoreChange) {
|
|
616
|
-
const matchMedia = getMatchMedia();
|
|
617
|
-
return matchMedia.addEventListener("change", onStoreChange), () => matchMedia.removeEventListener("change", onStoreChange);
|
|
589
|
+
const { media } = useTheme_v2(), store = useMemo(() => _createMediaStore(media), [media]);
|
|
590
|
+
return useSyncExternalStore(store.subscribe, store.getSnapshot, getServerSnapshot);
|
|
618
591
|
}
|
|
619
|
-
function
|
|
620
|
-
return
|
|
592
|
+
function usePrefersDark(getServerSnapshot2 = () => !1) {
|
|
593
|
+
return useMatchMedia("(prefers-color-scheme: dark)", getServerSnapshot2);
|
|
621
594
|
}
|
|
622
|
-
function
|
|
623
|
-
return
|
|
624
|
-
}
|
|
625
|
-
function usePrefersReducedMotion() {
|
|
626
|
-
return useSyncExternalStore(subscribe$1, getSnapshot, getServerSnapshot);
|
|
627
|
-
}
|
|
628
|
-
function useForwardedRef(ref) {
|
|
629
|
-
const innerRef = useRef(null);
|
|
630
|
-
return useImperativeHandle(ref, () => innerRef.current), innerRef;
|
|
631
|
-
}
|
|
632
|
-
function useCustomValidity(ref, customValidity) {
|
|
633
|
-
useEffect(() => {
|
|
634
|
-
var _a;
|
|
635
|
-
(_a = ref.current) == null || _a.setCustomValidity(customValidity || "");
|
|
636
|
-
}, [customValidity, ref]);
|
|
595
|
+
function usePrefersReducedMotion(getServerSnapshot2 = () => !1) {
|
|
596
|
+
return useMatchMedia("(prefers-reduced-motion: reduce)", getServerSnapshot2);
|
|
637
597
|
}
|
|
638
598
|
function responsiveBorderStyle() {
|
|
639
599
|
return [border, borderTop, borderRight, borderBottom, borderLeft];
|
|
@@ -3059,31 +3019,25 @@ function Portal(props) {
|
|
|
3059
3019
|
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);
|
|
3060
3020
|
return portalElement ? createPortal(children, portalElement) : null;
|
|
3061
3021
|
}
|
|
3062
|
-
function
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
return objA === objB;
|
|
3069
|
-
const keysA = Object.keys(objA), keysB = Object.keys(objB);
|
|
3070
|
-
return keysA.length !== keysB.length ? !1 : keysA.every((key2) => objA[key2] === objB[key2]);
|
|
3022
|
+
function useMounted() {
|
|
3023
|
+
return useSyncExternalStore(
|
|
3024
|
+
subscribe,
|
|
3025
|
+
() => !0,
|
|
3026
|
+
() => !1
|
|
3027
|
+
);
|
|
3071
3028
|
}
|
|
3029
|
+
const subscribe = () => () => {
|
|
3030
|
+
};
|
|
3072
3031
|
function PortalProvider(props) {
|
|
3073
|
-
const { boundaryElement, children, element, __unstable_elements:
|
|
3074
|
-
emptySubscribe,
|
|
3075
|
-
() => document.body,
|
|
3076
|
-
() => null
|
|
3077
|
-
), value = useMemo(() => ({
|
|
3032
|
+
const { boundaryElement, children, element, __unstable_elements: elements } = props, mounted = useMounted(), value = useMemo(() => ({
|
|
3078
3033
|
version: 0,
|
|
3079
3034
|
boundaryElement: boundaryElement || null,
|
|
3080
|
-
element: element ||
|
|
3035
|
+
element: element || mounted ? document.body : null,
|
|
3081
3036
|
elements
|
|
3082
|
-
}), [boundaryElement, element, elements,
|
|
3037
|
+
}), [boundaryElement, element, elements, mounted]);
|
|
3083
3038
|
return /* @__PURE__ */ jsx(PortalContext.Provider, { value, children });
|
|
3084
3039
|
}
|
|
3085
|
-
const
|
|
3086
|
-
}, Root$i = styled.div`
|
|
3040
|
+
const Root$i = styled.div`
|
|
3087
3041
|
display: block;
|
|
3088
3042
|
width: 0;
|
|
3089
3043
|
height: 0;
|
|
@@ -4443,14 +4397,6 @@ const Root$a = styled(Layer)`
|
|
|
4443
4397
|
[childProp == null ? void 0 : childProp.props, handleIsOpenChange]
|
|
4444
4398
|
);
|
|
4445
4399
|
useEffect(() => {
|
|
4446
|
-
if (!showTooltip) return;
|
|
4447
|
-
function handleWindowMouseMove(event) {
|
|
4448
|
-
referenceElement && (referenceElement === event.target || event.target instanceof Node && referenceElement.contains(event.target) || (handleIsOpenChange(!1), window.removeEventListener("mousemove", handleWindowMouseMove)));
|
|
4449
|
-
}
|
|
4450
|
-
return window.addEventListener("mousemove", handleWindowMouseMove), () => {
|
|
4451
|
-
window.removeEventListener("mousemove", handleWindowMouseMove);
|
|
4452
|
-
};
|
|
4453
|
-
}, [showTooltip, referenceElement, handleIsOpenChange]), useEffect(() => {
|
|
4454
4400
|
disabled && showTooltip && handleIsOpenChange(!1);
|
|
4455
4401
|
}, [disabled, handleIsOpenChange, showTooltip]), useEffect(() => {
|
|
4456
4402
|
!content && showTooltip && handleIsOpenChange(!1);
|
|
@@ -4462,7 +4408,7 @@ const Root$a = styled(Layer)`
|
|
|
4462
4408
|
return window.addEventListener("keydown", handleWindowKeyDown), () => {
|
|
4463
4409
|
window.removeEventListener("keydown", handleWindowKeyDown);
|
|
4464
4410
|
};
|
|
4465
|
-
}, [handleIsOpenChange, showTooltip]);
|
|
4411
|
+
}, [handleIsOpenChange, showTooltip]), useCloseOnMouseLeave({ handleIsOpenChange, referenceElement, showTooltip });
|
|
4466
4412
|
const setArrow = useCallback(
|
|
4467
4413
|
(arrowEl) => {
|
|
4468
4414
|
arrowRef.current = arrowEl, update();
|
|
@@ -4545,7 +4491,21 @@ const Root$a = styled(Layer)`
|
|
|
4545
4491
|
),
|
|
4546
4492
|
child
|
|
4547
4493
|
] });
|
|
4548
|
-
})
|
|
4494
|
+
});
|
|
4495
|
+
function useCloseOnMouseLeave({
|
|
4496
|
+
handleIsOpenChange,
|
|
4497
|
+
referenceElement,
|
|
4498
|
+
showTooltip
|
|
4499
|
+
}) {
|
|
4500
|
+
const handleWindowMouseMove = useEffectEvent((event) => {
|
|
4501
|
+
referenceElement && (referenceElement === event.target || event.target instanceof Node && referenceElement.contains(event.target) || handleIsOpenChange(!1));
|
|
4502
|
+
});
|
|
4503
|
+
useEffect(() => {
|
|
4504
|
+
if (showTooltip)
|
|
4505
|
+
return window.addEventListener("mousemove", handleWindowMouseMove), () => window.removeEventListener("mousemove", handleWindowMouseMove);
|
|
4506
|
+
}, [handleWindowMouseMove, showTooltip]);
|
|
4507
|
+
}
|
|
4508
|
+
const Root$9 = styled.div`
|
|
4549
4509
|
line-height: 0;
|
|
4550
4510
|
`, ListBox = styled(Box)`
|
|
4551
4511
|
& > ul {
|
|
@@ -4956,8 +4916,8 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
|
|
|
4956
4916
|
appearance: none;
|
|
4957
4917
|
margin: -4px;
|
|
4958
4918
|
`, Breadcrumbs = forwardRef(function(props, ref) {
|
|
4959
|
-
const { children, maxLength, separator, space: spaceRaw = 2, ...restProps } = props, space = useArrayProp(spaceRaw), [open, setOpen] = useState(!1),
|
|
4960
|
-
useClickOutside(collapse, [
|
|
4919
|
+
const { children, maxLength, separator, space: spaceRaw = 2, ...restProps } = props, space = useArrayProp(spaceRaw), [open, setOpen] = useState(!1), expandElementRef = useRef(null), popoverElementRef = useRef(null), collapse = useCallback(() => setOpen(!1), []), expand = useCallback(() => setOpen(!0), []);
|
|
4920
|
+
useClickOutside(collapse, () => [expandElementRef.current, popoverElementRef.current]);
|
|
4961
4921
|
const rawItems = useMemo(() => Children.toArray(children).filter(isValidElement), [children]), items = useMemo(() => {
|
|
4962
4922
|
const len = rawItems.length;
|
|
4963
4923
|
if (maxLength && len > maxLength) {
|
|
@@ -4972,7 +4932,7 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
|
|
|
4972
4932
|
open,
|
|
4973
4933
|
placement: "top",
|
|
4974
4934
|
portal: !0,
|
|
4975
|
-
ref:
|
|
4935
|
+
ref: popoverElementRef,
|
|
4976
4936
|
children: /* @__PURE__ */ jsx(
|
|
4977
4937
|
ExpandButton,
|
|
4978
4938
|
{
|
|
@@ -4980,7 +4940,7 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
|
|
|
4980
4940
|
mode: "bleed",
|
|
4981
4941
|
onClick: open ? collapse : expand,
|
|
4982
4942
|
padding: 1,
|
|
4983
|
-
ref:
|
|
4943
|
+
ref: expandElementRef,
|
|
4984
4944
|
selected: open,
|
|
4985
4945
|
text: "\u2026"
|
|
4986
4946
|
}
|
|
@@ -5105,8 +5065,8 @@ const Root$7 = styled(Layer)(responsivePaddingStyle, dialogStyle, responsiveDial
|
|
|
5105
5065
|
scheme,
|
|
5106
5066
|
shadow: shadowProp,
|
|
5107
5067
|
width: widthProp
|
|
5108
|
-
} = 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 = useRef(null),
|
|
5109
|
-
useImperativeHandle(forwardedRef, () => ref.current), useImperativeHandle(
|
|
5068
|
+
} = 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 = useRef(null), contentRef = useRef(null), layer = useLayer(), { isTopLayer } = layer, labelId = `${id}_label`, showCloseButton = !!onClose && hideCloseButton === !1, showHeader = !!header || showCloseButton;
|
|
5069
|
+
return useImperativeHandle(forwardedRef, () => ref.current), useImperativeHandle(
|
|
5110
5070
|
forwardedContentRef,
|
|
5111
5071
|
() => contentRef.current
|
|
5112
5072
|
), useEffect(() => {
|
|
@@ -5121,20 +5081,13 @@ const Root$7 = styled(Layer)(responsivePaddingStyle, dialogStyle, responsiveDial
|
|
|
5121
5081
|
[boundaryElement, isTopLayer, onClose, portalElement]
|
|
5122
5082
|
)
|
|
5123
5083
|
), useClickOutside(
|
|
5124
|
-
|
|
5125
|
-
(
|
|
5126
|
-
|
|
5127
|
-
|
|
5128
|
-
|
|
5129
|
-
|
|
5130
|
-
|
|
5131
|
-
),
|
|
5132
|
-
[rootElement]
|
|
5133
|
-
);
|
|
5134
|
-
const setRef = useCallback((el) => {
|
|
5135
|
-
setRootElement(el), ref.current = el;
|
|
5136
|
-
}, []);
|
|
5137
|
-
return /* @__PURE__ */ jsx(DialogContainer, { "data-ui": "DialogCard", width, children: /* @__PURE__ */ jsx(DialogCardRoot, { radius, ref: setRef, scheme, shadow, children: /* @__PURE__ */ jsxs(DialogLayout, { direction: "column", children: [
|
|
5084
|
+
(event) => {
|
|
5085
|
+
if (!isTopLayer || !onClickOutside) return;
|
|
5086
|
+
const target = event.target;
|
|
5087
|
+
target && !isTargetWithinScope(boundaryElement, portalElement, target) || onClickOutside();
|
|
5088
|
+
},
|
|
5089
|
+
() => [ref.current]
|
|
5090
|
+
), /* @__PURE__ */ jsx(DialogContainer, { "data-ui": "DialogCard", width, children: /* @__PURE__ */ jsx(DialogCardRoot, { radius, ref, scheme, shadow, children: /* @__PURE__ */ jsxs(DialogLayout, { direction: "column", children: [
|
|
5138
5091
|
showHeader && /* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsxs(Flex, { align: "center", padding: 3, children: [
|
|
5139
5092
|
/* @__PURE__ */ jsx(Box, { flex: 1, padding: 2, children: header && /* @__PURE__ */ jsx(Text, { id: labelId, size: 1, weight: "semibold", children: header }) }),
|
|
5140
5093
|
showCloseButton && /* @__PURE__ */ jsx(Box, { flex: "none", children: /* @__PURE__ */ jsx(
|
|
@@ -5312,13 +5265,13 @@ function _sortElements(rootElement, elements) {
|
|
|
5312
5265
|
elements.sort(_sort);
|
|
5313
5266
|
}
|
|
5314
5267
|
function useMenuController(props) {
|
|
5315
|
-
const { onKeyDown, originElement, shouldFocus } = props, elementsRef = useRef([]), [
|
|
5268
|
+
const { onKeyDown, originElement, shouldFocus, rootElementRef } = props, elementsRef = useRef([]), [activeIndex, _setActiveIndex] = useState(-1), activeIndexRef = useRef(activeIndex), activeElement = useMemo(() => elementsRef.current[activeIndex] || null, [activeIndex]), mounted = !!rootElementRef.current, setActiveIndex = useCallback((nextActiveIndex) => {
|
|
5316
5269
|
_setActiveIndex(nextActiveIndex), activeIndexRef.current = nextActiveIndex;
|
|
5317
5270
|
}, []), mount = useCallback(
|
|
5318
5271
|
(element, selected) => {
|
|
5319
5272
|
if (!element) return () => {
|
|
5320
5273
|
};
|
|
5321
|
-
if (elementsRef.current.indexOf(element) === -1 && (elementsRef.current.push(element), _sortElements(
|
|
5274
|
+
if (elementsRef.current.indexOf(element) === -1 && (elementsRef.current.push(element), _sortElements(rootElementRef.current, elementsRef.current)), selected) {
|
|
5322
5275
|
const selectedIndex = elementsRef.current.indexOf(element);
|
|
5323
5276
|
setActiveIndex(selectedIndex);
|
|
5324
5277
|
}
|
|
@@ -5327,7 +5280,7 @@ function useMenuController(props) {
|
|
|
5327
5280
|
idx > -1 && elementsRef.current.splice(idx, 1);
|
|
5328
5281
|
};
|
|
5329
5282
|
},
|
|
5330
|
-
[
|
|
5283
|
+
[rootElementRef, setActiveIndex]
|
|
5331
5284
|
), handleKeyDown = useCallback(
|
|
5332
5285
|
(event) => {
|
|
5333
5286
|
if (event.key === "Tab") {
|
|
@@ -5382,13 +5335,13 @@ function useMenuController(props) {
|
|
|
5382
5335
|
},
|
|
5383
5336
|
[setActiveIndex]
|
|
5384
5337
|
), handleItemMouseLeave = useCallback(() => {
|
|
5385
|
-
|
|
5386
|
-
|
|
5338
|
+
var _a;
|
|
5339
|
+
setActiveIndex(-2), (_a = rootElementRef.current) == null || _a.focus();
|
|
5340
|
+
}, [rootElementRef, setActiveIndex]);
|
|
5387
5341
|
return useEffect(() => {
|
|
5388
5342
|
if (!mounted) return;
|
|
5389
5343
|
const rafId = window.requestAnimationFrame(() => {
|
|
5390
|
-
|
|
5391
|
-
if (_activeIndex === -1) {
|
|
5344
|
+
if (activeIndex === -1) {
|
|
5392
5345
|
if (shouldFocus === "first") {
|
|
5393
5346
|
const el = _getFocusableElements(elementsRef.current)[0];
|
|
5394
5347
|
if (el) {
|
|
@@ -5405,7 +5358,7 @@ function useMenuController(props) {
|
|
|
5405
5358
|
}
|
|
5406
5359
|
return;
|
|
5407
5360
|
}
|
|
5408
|
-
const element = elementsRef.current[
|
|
5361
|
+
const element = elementsRef.current[activeIndex] || null;
|
|
5409
5362
|
element == null || element.focus();
|
|
5410
5363
|
});
|
|
5411
5364
|
return () => {
|
|
@@ -5417,9 +5370,7 @@ function useMenuController(props) {
|
|
|
5417
5370
|
handleItemMouseEnter,
|
|
5418
5371
|
handleItemMouseLeave,
|
|
5419
5372
|
handleKeyDown,
|
|
5420
|
-
mount
|
|
5421
|
-
rootElement,
|
|
5422
|
-
setRootElement
|
|
5373
|
+
mount
|
|
5423
5374
|
};
|
|
5424
5375
|
}
|
|
5425
5376
|
const Root$5 = styled(Box)`
|
|
@@ -5451,23 +5402,18 @@ const Root$5 = styled(Box)`
|
|
|
5451
5402
|
handleItemMouseEnter,
|
|
5452
5403
|
handleItemMouseLeave,
|
|
5453
5404
|
handleKeyDown,
|
|
5454
|
-
mount
|
|
5455
|
-
|
|
5456
|
-
setRootElement
|
|
5457
|
-
} = useMenuController({ onKeyDown, originElement, shouldFocus }), handleRefChange = useCallback(
|
|
5405
|
+
mount
|
|
5406
|
+
} = useMenuController({ onKeyDown, originElement, shouldFocus, rootElementRef: ref }), handleRefChange = useCallback(
|
|
5458
5407
|
(el) => {
|
|
5459
|
-
|
|
5408
|
+
ref.current = el, ref.current && registerElement && registerElement(ref.current);
|
|
5460
5409
|
},
|
|
5461
|
-
[
|
|
5410
|
+
[registerElement]
|
|
5462
5411
|
);
|
|
5463
5412
|
useEffect(() => {
|
|
5464
5413
|
onItemSelect && onItemSelect(activeIndex);
|
|
5465
5414
|
}, [activeIndex, onItemSelect]), useClickOutside(
|
|
5466
|
-
|
|
5467
|
-
|
|
5468
|
-
[isTopLayer, onClickOutside]
|
|
5469
|
-
),
|
|
5470
|
-
[rootElement]
|
|
5415
|
+
(event) => isTopLayer && onClickOutside && onClickOutside(event),
|
|
5416
|
+
() => [ref.current]
|
|
5471
5417
|
), useGlobalKeyDown(
|
|
5472
5418
|
useCallback(
|
|
5473
5419
|
(event) => {
|
|
@@ -5475,10 +5421,7 @@ const Root$5 = styled(Box)`
|
|
|
5475
5421
|
},
|
|
5476
5422
|
[isTopLayer, onEscape]
|
|
5477
5423
|
)
|
|
5478
|
-
)
|
|
5479
|
-
if (!(!rootElement || !registerElement))
|
|
5480
|
-
return registerElement(rootElement);
|
|
5481
|
-
}, [registerElement, rootElement]);
|
|
5424
|
+
);
|
|
5482
5425
|
const value = useMemo(
|
|
5483
5426
|
() => ({
|
|
5484
5427
|
version: 0,
|
|
@@ -6240,15 +6183,7 @@ function Toast(props) {
|
|
|
6240
6183
|
}
|
|
6241
6184
|
);
|
|
6242
6185
|
}
|
|
6243
|
-
|
|
6244
|
-
return useSyncExternalStore(
|
|
6245
|
-
subscribe,
|
|
6246
|
-
() => !0,
|
|
6247
|
-
() => !1
|
|
6248
|
-
);
|
|
6249
|
-
}
|
|
6250
|
-
const subscribe = () => () => {
|
|
6251
|
-
}, key$1 = Symbol.for("@sanity/ui/context/toast"), ToastContext = createGlobalScopedContext(key$1, null), Root$1 = styled(Layer)`
|
|
6186
|
+
const key$1 = Symbol.for("@sanity/ui/context/toast"), ToastContext = createGlobalScopedContext(key$1, null), Root$1 = styled(Layer)`
|
|
6252
6187
|
position: fixed;
|
|
6253
6188
|
top: 0;
|
|
6254
6189
|
left: 0;
|
|
@@ -6860,6 +6795,7 @@ export {
|
|
|
6860
6795
|
useForwardedRef,
|
|
6861
6796
|
useGlobalKeyDown,
|
|
6862
6797
|
useLayer,
|
|
6798
|
+
useMatchMedia,
|
|
6863
6799
|
useMediaIndex,
|
|
6864
6800
|
usePortal,
|
|
6865
6801
|
usePrefersDark,
|