@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.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var theme = require("@sanity/ui/theme"), jsxRuntime = require("react/jsx-runtime"), react = require("react"), ReactIs = require("react-is"), styledComponents = require("styled-components"), icons = require("@sanity/icons"), Refractor = require("react-refractor"), reactDom$1 = require("@floating-ui/react-dom"), framerMotion = require("framer-motion"), reactDom = require("react-dom"), getTheme_v2 = require("./_chunks-cjs/getTheme_v2.js");
|
|
3
|
+
var theme = require("@sanity/ui/theme"), jsxRuntime = require("react/jsx-runtime"), react = require("react"), ReactIs = require("react-is"), styledComponents = require("styled-components"), icons = require("@sanity/icons"), Refractor = require("react-refractor"), reactDom$1 = require("@floating-ui/react-dom"), framerMotion = require("framer-motion"), reactDom = require("react-dom"), useEffectEvent = require("use-effect-event"), getTheme_v2 = require("./_chunks-cjs/getTheme_v2.js");
|
|
4
4
|
function _interopDefaultCompat(e) {
|
|
5
5
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
6
|
}
|
|
@@ -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;
|
|
134
|
+
const elements = (Array.isArray(elementsArg) ? elementsArg : elementsArg()).flat();
|
|
135
|
+
for (const el of elements)
|
|
136
|
+
if (el && (target === el || el.contains(target)))
|
|
146
137
|
return;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
for (const el of elements)
|
|
159
|
-
if (target === el || el.contains(target))
|
|
160
|
-
return;
|
|
161
|
-
listener(evt);
|
|
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);
|
|
589
|
-
}
|
|
590
|
-
let MEDIA_QUERY_CACHE$1;
|
|
591
|
-
function getMatchMedia$1() {
|
|
592
|
-
return MEDIA_QUERY_CACHE$1 || (MEDIA_QUERY_CACHE$1 = window.matchMedia("(prefers-color-scheme: dark)")), MEDIA_QUERY_CACHE$1;
|
|
593
|
-
}
|
|
594
|
-
function subscribe$2(onStoreChange) {
|
|
595
|
-
const matchMedia = getMatchMedia$1();
|
|
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);
|
|
584
|
+
const { media } = useTheme_v2(), store = react.useMemo(() => _createMediaStore(media), [media]);
|
|
585
|
+
return react.useSyncExternalStore(store.subscribe, store.getSnapshot, getServerSnapshot);
|
|
614
586
|
}
|
|
615
|
-
function
|
|
616
|
-
return
|
|
587
|
+
function usePrefersDark(getServerSnapshot2 = () => !1) {
|
|
588
|
+
return useMatchMedia("(prefers-color-scheme: dark)", getServerSnapshot2);
|
|
617
589
|
}
|
|
618
|
-
function
|
|
619
|
-
return
|
|
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,31 +3014,25 @@ 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
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
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]);
|
|
3017
|
+
function useMounted() {
|
|
3018
|
+
return react.useSyncExternalStore(
|
|
3019
|
+
subscribe,
|
|
3020
|
+
() => !0,
|
|
3021
|
+
() => !1
|
|
3022
|
+
);
|
|
3067
3023
|
}
|
|
3024
|
+
const subscribe = () => () => {
|
|
3025
|
+
};
|
|
3068
3026
|
function PortalProvider(props) {
|
|
3069
|
-
const { boundaryElement, children, element, __unstable_elements:
|
|
3070
|
-
emptySubscribe,
|
|
3071
|
-
() => document.body,
|
|
3072
|
-
() => null
|
|
3073
|
-
), value = react.useMemo(() => ({
|
|
3027
|
+
const { boundaryElement, children, element, __unstable_elements: elements } = props, mounted = useMounted(), value = react.useMemo(() => ({
|
|
3074
3028
|
version: 0,
|
|
3075
3029
|
boundaryElement: boundaryElement || null,
|
|
3076
|
-
element: element ||
|
|
3030
|
+
element: element || mounted ? document.body : null,
|
|
3077
3031
|
elements
|
|
3078
|
-
}), [boundaryElement, element, elements,
|
|
3032
|
+
}), [boundaryElement, element, elements, mounted]);
|
|
3079
3033
|
return /* @__PURE__ */ jsxRuntime.jsx(PortalContext.Provider, { value, children });
|
|
3080
3034
|
}
|
|
3081
|
-
const
|
|
3082
|
-
}, Root$i = styledComponents.styled.div`
|
|
3035
|
+
const Root$i = styledComponents.styled.div`
|
|
3083
3036
|
display: block;
|
|
3084
3037
|
width: 0;
|
|
3085
3038
|
height: 0;
|
|
@@ -4439,14 +4392,6 @@ const Root$a = styledComponents.styled(Layer)`
|
|
|
4439
4392
|
[childProp == null ? void 0 : childProp.props, handleIsOpenChange]
|
|
4440
4393
|
);
|
|
4441
4394
|
react.useEffect(() => {
|
|
4442
|
-
if (!showTooltip) return;
|
|
4443
|
-
function handleWindowMouseMove(event) {
|
|
4444
|
-
referenceElement && (referenceElement === event.target || event.target instanceof Node && referenceElement.contains(event.target) || (handleIsOpenChange(!1), window.removeEventListener("mousemove", handleWindowMouseMove)));
|
|
4445
|
-
}
|
|
4446
|
-
return window.addEventListener("mousemove", handleWindowMouseMove), () => {
|
|
4447
|
-
window.removeEventListener("mousemove", handleWindowMouseMove);
|
|
4448
|
-
};
|
|
4449
|
-
}, [showTooltip, referenceElement, handleIsOpenChange]), react.useEffect(() => {
|
|
4450
4395
|
disabled && showTooltip && handleIsOpenChange(!1);
|
|
4451
4396
|
}, [disabled, handleIsOpenChange, showTooltip]), react.useEffect(() => {
|
|
4452
4397
|
!content && showTooltip && handleIsOpenChange(!1);
|
|
@@ -4458,7 +4403,7 @@ const Root$a = styledComponents.styled(Layer)`
|
|
|
4458
4403
|
return window.addEventListener("keydown", handleWindowKeyDown), () => {
|
|
4459
4404
|
window.removeEventListener("keydown", handleWindowKeyDown);
|
|
4460
4405
|
};
|
|
4461
|
-
}, [handleIsOpenChange, showTooltip]);
|
|
4406
|
+
}, [handleIsOpenChange, showTooltip]), useCloseOnMouseLeave({ handleIsOpenChange, referenceElement, showTooltip });
|
|
4462
4407
|
const setArrow = react.useCallback(
|
|
4463
4408
|
(arrowEl) => {
|
|
4464
4409
|
arrowRef.current = arrowEl, update();
|
|
@@ -4541,7 +4486,21 @@ const Root$a = styledComponents.styled(Layer)`
|
|
|
4541
4486
|
),
|
|
4542
4487
|
child
|
|
4543
4488
|
] });
|
|
4544
|
-
})
|
|
4489
|
+
});
|
|
4490
|
+
function useCloseOnMouseLeave({
|
|
4491
|
+
handleIsOpenChange,
|
|
4492
|
+
referenceElement,
|
|
4493
|
+
showTooltip
|
|
4494
|
+
}) {
|
|
4495
|
+
const handleWindowMouseMove = useEffectEvent.useEffectEvent((event) => {
|
|
4496
|
+
referenceElement && (referenceElement === event.target || event.target instanceof Node && referenceElement.contains(event.target) || handleIsOpenChange(!1));
|
|
4497
|
+
});
|
|
4498
|
+
react.useEffect(() => {
|
|
4499
|
+
if (showTooltip)
|
|
4500
|
+
return window.addEventListener("mousemove", handleWindowMouseMove), () => window.removeEventListener("mousemove", handleWindowMouseMove);
|
|
4501
|
+
}, [handleWindowMouseMove, showTooltip]);
|
|
4502
|
+
}
|
|
4503
|
+
const Root$9 = styledComponents.styled.div`
|
|
4545
4504
|
line-height: 0;
|
|
4546
4505
|
`, ListBox = styledComponents.styled(Box)`
|
|
4547
4506
|
& > ul {
|
|
@@ -4952,8 +4911,8 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
|
|
|
4952
4911
|
appearance: none;
|
|
4953
4912
|
margin: -4px;
|
|
4954
4913
|
`, Breadcrumbs = react.forwardRef(function(props, ref) {
|
|
4955
|
-
const { children, maxLength, separator, space: spaceRaw = 2, ...restProps } = props, space = useArrayProp(spaceRaw), [open, setOpen] = react.useState(!1),
|
|
4956
|
-
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]);
|
|
4957
4916
|
const rawItems = react.useMemo(() => react.Children.toArray(children).filter(react.isValidElement), [children]), items = react.useMemo(() => {
|
|
4958
4917
|
const len = rawItems.length;
|
|
4959
4918
|
if (maxLength && len > maxLength) {
|
|
@@ -4968,7 +4927,7 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
|
|
|
4968
4927
|
open,
|
|
4969
4928
|
placement: "top",
|
|
4970
4929
|
portal: !0,
|
|
4971
|
-
ref:
|
|
4930
|
+
ref: popoverElementRef,
|
|
4972
4931
|
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4973
4932
|
ExpandButton,
|
|
4974
4933
|
{
|
|
@@ -4976,7 +4935,7 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
|
|
|
4976
4935
|
mode: "bleed",
|
|
4977
4936
|
onClick: open ? collapse : expand,
|
|
4978
4937
|
padding: 1,
|
|
4979
|
-
ref:
|
|
4938
|
+
ref: expandElementRef,
|
|
4980
4939
|
selected: open,
|
|
4981
4940
|
text: "\u2026"
|
|
4982
4941
|
}
|
|
@@ -5101,8 +5060,8 @@ const Root$7 = styledComponents.styled(Layer)(responsivePaddingStyle, dialogStyl
|
|
|
5101
5060
|
scheme,
|
|
5102
5061
|
shadow: shadowProp,
|
|
5103
5062
|
width: widthProp
|
|
5104
|
-
} = 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),
|
|
5105
|
-
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(
|
|
5106
5065
|
forwardedContentRef,
|
|
5107
5066
|
() => contentRef.current
|
|
5108
5067
|
), react.useEffect(() => {
|
|
@@ -5117,20 +5076,13 @@ const Root$7 = styledComponents.styled(Layer)(responsivePaddingStyle, dialogStyl
|
|
|
5117
5076
|
[boundaryElement, isTopLayer, onClose, portalElement]
|
|
5118
5077
|
)
|
|
5119
5078
|
), useClickOutside(
|
|
5120
|
-
|
|
5121
|
-
(
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
),
|
|
5128
|
-
[rootElement]
|
|
5129
|
-
);
|
|
5130
|
-
const setRef = react.useCallback((el) => {
|
|
5131
|
-
setRootElement(el), ref.current = el;
|
|
5132
|
-
}, []);
|
|
5133
|
-
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: [
|
|
5134
5086
|
showHeader && /* @__PURE__ */ jsxRuntime.jsx(DialogHeader, { children: /* @__PURE__ */ jsxRuntime.jsxs(Flex, { align: "center", padding: 3, children: [
|
|
5135
5087
|
/* @__PURE__ */ jsxRuntime.jsx(Box, { flex: 1, padding: 2, children: header && /* @__PURE__ */ jsxRuntime.jsx(Text, { id: labelId, size: 1, weight: "semibold", children: header }) }),
|
|
5136
5088
|
showCloseButton && /* @__PURE__ */ jsxRuntime.jsx(Box, { flex: "none", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -5308,13 +5260,13 @@ function _sortElements(rootElement, elements) {
|
|
|
5308
5260
|
elements.sort(_sort);
|
|
5309
5261
|
}
|
|
5310
5262
|
function useMenuController(props) {
|
|
5311
|
-
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) => {
|
|
5312
5264
|
_setActiveIndex(nextActiveIndex), activeIndexRef.current = nextActiveIndex;
|
|
5313
5265
|
}, []), mount = react.useCallback(
|
|
5314
5266
|
(element, selected) => {
|
|
5315
5267
|
if (!element) return () => {
|
|
5316
5268
|
};
|
|
5317
|
-
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) {
|
|
5318
5270
|
const selectedIndex = elementsRef.current.indexOf(element);
|
|
5319
5271
|
setActiveIndex(selectedIndex);
|
|
5320
5272
|
}
|
|
@@ -5323,7 +5275,7 @@ function useMenuController(props) {
|
|
|
5323
5275
|
idx > -1 && elementsRef.current.splice(idx, 1);
|
|
5324
5276
|
};
|
|
5325
5277
|
},
|
|
5326
|
-
[
|
|
5278
|
+
[rootElementRef, setActiveIndex]
|
|
5327
5279
|
), handleKeyDown = react.useCallback(
|
|
5328
5280
|
(event) => {
|
|
5329
5281
|
if (event.key === "Tab") {
|
|
@@ -5378,13 +5330,13 @@ function useMenuController(props) {
|
|
|
5378
5330
|
},
|
|
5379
5331
|
[setActiveIndex]
|
|
5380
5332
|
), handleItemMouseLeave = react.useCallback(() => {
|
|
5381
|
-
|
|
5382
|
-
|
|
5333
|
+
var _a;
|
|
5334
|
+
setActiveIndex(-2), (_a = rootElementRef.current) == null || _a.focus();
|
|
5335
|
+
}, [rootElementRef, setActiveIndex]);
|
|
5383
5336
|
return react.useEffect(() => {
|
|
5384
5337
|
if (!mounted) return;
|
|
5385
5338
|
const rafId = window.requestAnimationFrame(() => {
|
|
5386
|
-
|
|
5387
|
-
if (_activeIndex === -1) {
|
|
5339
|
+
if (activeIndex === -1) {
|
|
5388
5340
|
if (shouldFocus === "first") {
|
|
5389
5341
|
const el = _getFocusableElements(elementsRef.current)[0];
|
|
5390
5342
|
if (el) {
|
|
@@ -5401,7 +5353,7 @@ function useMenuController(props) {
|
|
|
5401
5353
|
}
|
|
5402
5354
|
return;
|
|
5403
5355
|
}
|
|
5404
|
-
const element = elementsRef.current[
|
|
5356
|
+
const element = elementsRef.current[activeIndex] || null;
|
|
5405
5357
|
element == null || element.focus();
|
|
5406
5358
|
});
|
|
5407
5359
|
return () => {
|
|
@@ -5413,9 +5365,7 @@ function useMenuController(props) {
|
|
|
5413
5365
|
handleItemMouseEnter,
|
|
5414
5366
|
handleItemMouseLeave,
|
|
5415
5367
|
handleKeyDown,
|
|
5416
|
-
mount
|
|
5417
|
-
rootElement,
|
|
5418
|
-
setRootElement
|
|
5368
|
+
mount
|
|
5419
5369
|
};
|
|
5420
5370
|
}
|
|
5421
5371
|
const Root$5 = styledComponents.styled(Box)`
|
|
@@ -5447,23 +5397,18 @@ const Root$5 = styledComponents.styled(Box)`
|
|
|
5447
5397
|
handleItemMouseEnter,
|
|
5448
5398
|
handleItemMouseLeave,
|
|
5449
5399
|
handleKeyDown,
|
|
5450
|
-
mount
|
|
5451
|
-
|
|
5452
|
-
setRootElement
|
|
5453
|
-
} = useMenuController({ onKeyDown, originElement, shouldFocus }), handleRefChange = react.useCallback(
|
|
5400
|
+
mount
|
|
5401
|
+
} = useMenuController({ onKeyDown, originElement, shouldFocus, rootElementRef: ref }), handleRefChange = react.useCallback(
|
|
5454
5402
|
(el) => {
|
|
5455
|
-
|
|
5403
|
+
ref.current = el, ref.current && registerElement && registerElement(ref.current);
|
|
5456
5404
|
},
|
|
5457
|
-
[
|
|
5405
|
+
[registerElement]
|
|
5458
5406
|
);
|
|
5459
5407
|
react.useEffect(() => {
|
|
5460
5408
|
onItemSelect && onItemSelect(activeIndex);
|
|
5461
5409
|
}, [activeIndex, onItemSelect]), useClickOutside(
|
|
5462
|
-
|
|
5463
|
-
|
|
5464
|
-
[isTopLayer, onClickOutside]
|
|
5465
|
-
),
|
|
5466
|
-
[rootElement]
|
|
5410
|
+
(event) => isTopLayer && onClickOutside && onClickOutside(event),
|
|
5411
|
+
() => [ref.current]
|
|
5467
5412
|
), useGlobalKeyDown(
|
|
5468
5413
|
react.useCallback(
|
|
5469
5414
|
(event) => {
|
|
@@ -5471,10 +5416,7 @@ const Root$5 = styledComponents.styled(Box)`
|
|
|
5471
5416
|
},
|
|
5472
5417
|
[isTopLayer, onEscape]
|
|
5473
5418
|
)
|
|
5474
|
-
)
|
|
5475
|
-
if (!(!rootElement || !registerElement))
|
|
5476
|
-
return registerElement(rootElement);
|
|
5477
|
-
}, [registerElement, rootElement]);
|
|
5419
|
+
);
|
|
5478
5420
|
const value = react.useMemo(
|
|
5479
5421
|
() => ({
|
|
5480
5422
|
version: 0,
|
|
@@ -6236,15 +6178,7 @@ function Toast(props) {
|
|
|
6236
6178
|
}
|
|
6237
6179
|
);
|
|
6238
6180
|
}
|
|
6239
|
-
|
|
6240
|
-
return react.useSyncExternalStore(
|
|
6241
|
-
subscribe,
|
|
6242
|
-
() => !0,
|
|
6243
|
-
() => !1
|
|
6244
|
-
);
|
|
6245
|
-
}
|
|
6246
|
-
const subscribe = () => () => {
|
|
6247
|
-
}, key$1 = Symbol.for("@sanity/ui/context/toast"), ToastContext = createGlobalScopedContext(key$1, null), Root$1 = styledComponents.styled(Layer)`
|
|
6181
|
+
const key$1 = Symbol.for("@sanity/ui/context/toast"), ToastContext = createGlobalScopedContext(key$1, null), Root$1 = styledComponents.styled(Layer)`
|
|
6248
6182
|
position: fixed;
|
|
6249
6183
|
top: 0;
|
|
6250
6184
|
left: 0;
|
|
@@ -6855,6 +6789,7 @@ exports.useElementSize = useElementSize;
|
|
|
6855
6789
|
exports.useForwardedRef = useForwardedRef;
|
|
6856
6790
|
exports.useGlobalKeyDown = useGlobalKeyDown;
|
|
6857
6791
|
exports.useLayer = useLayer;
|
|
6792
|
+
exports.useMatchMedia = useMatchMedia;
|
|
6858
6793
|
exports.useMediaIndex = useMediaIndex;
|
|
6859
6794
|
exports.usePortal = usePortal;
|
|
6860
6795
|
exports.usePrefersDark = usePrefersDark;
|