@sanity/ui 2.6.7-canary.0 → 2.6.7
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 +15 -51
- package/dist/index.d.ts +15 -51
- package/dist/index.esm.js +186 -120
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +186 -119
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +186 -120
- 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 +53 -46
- package/src/core/__workshop__/constants.ts +36 -36
- package/src/core/components/autocomplete/autocomplete.tsx +1 -1
- package/src/core/components/breadcrumbs/breadcrumbs.tsx +6 -15
- package/src/core/components/dialog/dialog.tsx +21 -12
- package/src/core/components/dialog/styles.ts +8 -8
- package/src/core/components/menu/menu.tsx +18 -11
- 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 +17 -11
- package/src/core/components/tab/tab.tsx +8 -8
- package/src/core/components/tab/tabPanel.tsx +1 -1
- package/src/core/components/toast/styles.ts +1 -2
- package/src/core/components/toast/useToast.ts +0 -1
- package/src/core/components/tree/tree.tsx +0 -1
- package/src/core/components/tree/treeItem.tsx +0 -1
- package/src/core/helpers/focus.ts +0 -1
- package/src/core/helpers/scroll.ts +0 -1
- package/src/core/hooks/_internal/index.ts +1 -0
- package/src/core/hooks/_internal/useUnique.ts +34 -0
- package/src/core/hooks/index.ts +2 -3
- package/src/core/hooks/useClickOutside.ts +72 -38
- package/src/core/hooks/useElementSize.ts +0 -1
- package/src/core/hooks/useMediaIndex/useMediaIndex.ts +10 -2
- package/src/core/hooks/usePrefersDark.ts +55 -10
- package/src/core/hooks/usePrefersReducedMotion.ts +56 -10
- 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 +7 -9
- 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 +7 -9
- package/src/core/primitives/tooltip/constants.ts +4 -4
- package/src/core/primitives/tooltip/tooltip.tsx +49 -68
- package/src/core/primitives/tooltip/tooltipDelayGroup/tooltipDelayGroupProvider.tsx +0 -1
- 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 +0 -1
- package/src/core/utils/portal/__workshop__/named.tsx +8 -10
- package/src/core/utils/portal/portalProvider.tsx +13 -7
- 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/useMatchMedia.ts +0 -46
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"),
|
|
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");
|
|
4
4
|
function _interopDefaultCompat(e) {
|
|
5
5
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
6
|
}
|
|
@@ -126,26 +126,45 @@ 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
|
+
}
|
|
129
135
|
function useClickOutside(listener, elementsArg = EMPTY_ARRAY, boundaryElement) {
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
136
|
+
const [element, setElement] = react.useState(null), [elements, setElements] = react.useState(() => _getElements(element, elementsArg)), elementsRef = react.useRef(elements);
|
|
137
|
+
return react.useEffect(() => {
|
|
138
|
+
const prevElements = elementsRef.current, nextElements = _getElements(element, elementsArg);
|
|
139
|
+
if (prevElements.length !== nextElements.length) {
|
|
140
|
+
setElements(nextElements), elementsRef.current = nextElements;
|
|
133
141
|
return;
|
|
134
|
-
|
|
135
|
-
for (const el of
|
|
136
|
-
if (
|
|
142
|
+
}
|
|
143
|
+
for (const el of prevElements)
|
|
144
|
+
if (!nextElements.includes(el)) {
|
|
145
|
+
setElements(nextElements), elementsRef.current = nextElements;
|
|
137
146
|
return;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
147
|
+
}
|
|
148
|
+
for (const el of nextElements)
|
|
149
|
+
if (!prevElements.includes(el)) {
|
|
150
|
+
setElements(nextElements), elementsRef.current = nextElements;
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
}, [element, elementsArg]), react.useEffect(() => {
|
|
154
|
+
if (!listener) return;
|
|
155
|
+
const handleWindowMouseDown = (evt) => {
|
|
156
|
+
const target = evt.target;
|
|
157
|
+
if (target instanceof Node && !(boundaryElement && !boundaryElement.contains(target))) {
|
|
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;
|
|
149
168
|
}
|
|
150
169
|
var resizeObservers = [], hasActiveObservations = function() {
|
|
151
170
|
return resizeObservers.some(function(ro) {
|
|
@@ -480,27 +499,9 @@ function useElementRect(element) {
|
|
|
480
499
|
const elementSize = useElementSize(element);
|
|
481
500
|
return (elementSize == null ? void 0 : elementSize._contentRect) || null;
|
|
482
501
|
}
|
|
483
|
-
function useForwardedRef(ref) {
|
|
484
|
-
const innerRef = react.useRef(null);
|
|
485
|
-
return react.useImperativeHandle(ref, () => innerRef.current), innerRef;
|
|
486
|
-
}
|
|
487
502
|
function useGlobalKeyDown(onKeyDown) {
|
|
488
503
|
return react.useEffect(() => (addEventListener("keydown", onKeyDown), () => removeEventListener("keydown", onKeyDown)), [onKeyDown]);
|
|
489
504
|
}
|
|
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
|
-
}
|
|
504
505
|
function getGlobalScope() {
|
|
505
506
|
if (typeof globalThis < "u") return globalThis;
|
|
506
507
|
if (typeof window < "u") return window;
|
|
@@ -543,6 +544,7 @@ function useTheme() {
|
|
|
543
544
|
function useTheme_v2() {
|
|
544
545
|
return theme.getTheme_v2(styledComponents.useTheme());
|
|
545
546
|
}
|
|
547
|
+
const MEDIA_STORE_CACHE = /* @__PURE__ */ new WeakMap();
|
|
546
548
|
function _getMediaQuery(media, index) {
|
|
547
549
|
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)`;
|
|
548
550
|
}
|
|
@@ -577,18 +579,57 @@ function _createMediaStore(media) {
|
|
|
577
579
|
};
|
|
578
580
|
} };
|
|
579
581
|
}
|
|
580
|
-
function getServerSnapshot() {
|
|
582
|
+
function getServerSnapshot$2() {
|
|
581
583
|
return 0;
|
|
582
584
|
}
|
|
583
585
|
function useMediaIndex() {
|
|
584
|
-
const { media } = useTheme_v2()
|
|
585
|
-
|
|
586
|
+
const { media } = useTheme_v2();
|
|
587
|
+
let store = MEDIA_STORE_CACHE.get(media);
|
|
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);
|
|
614
|
+
}
|
|
615
|
+
function getSnapshot() {
|
|
616
|
+
return getMatchMedia().matches;
|
|
617
|
+
}
|
|
618
|
+
function getServerSnapshot() {
|
|
619
|
+
return !1;
|
|
586
620
|
}
|
|
587
|
-
function
|
|
588
|
-
return
|
|
621
|
+
function usePrefersReducedMotion() {
|
|
622
|
+
return react.useSyncExternalStore(subscribe$1, getSnapshot, getServerSnapshot);
|
|
589
623
|
}
|
|
590
|
-
function
|
|
591
|
-
|
|
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]);
|
|
592
633
|
}
|
|
593
634
|
function responsiveBorderStyle() {
|
|
594
635
|
return [border, borderTop, borderRight, borderBottom, borderLeft];
|
|
@@ -3014,25 +3055,31 @@ function Portal(props) {
|
|
|
3014
3055
|
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);
|
|
3015
3056
|
return portalElement ? reactDom.createPortal(children, portalElement) : null;
|
|
3016
3057
|
}
|
|
3017
|
-
function
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
)
|
|
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]);
|
|
3023
3067
|
}
|
|
3024
|
-
const subscribe = () => () => {
|
|
3025
|
-
};
|
|
3026
3068
|
function PortalProvider(props) {
|
|
3027
|
-
const { boundaryElement, children, element, __unstable_elements:
|
|
3069
|
+
const { boundaryElement, children, element, __unstable_elements: elementsProp } = props, elements = useUnique(elementsProp), fallbackElement = react.useSyncExternalStore(
|
|
3070
|
+
emptySubscribe$1,
|
|
3071
|
+
() => document.body,
|
|
3072
|
+
() => null
|
|
3073
|
+
), value = react.useMemo(() => ({
|
|
3028
3074
|
version: 0,
|
|
3029
3075
|
boundaryElement: boundaryElement || null,
|
|
3030
|
-
element: element ||
|
|
3076
|
+
element: element || fallbackElement,
|
|
3031
3077
|
elements
|
|
3032
|
-
}), [boundaryElement, element, elements,
|
|
3078
|
+
}), [boundaryElement, element, elements, fallbackElement]);
|
|
3033
3079
|
return /* @__PURE__ */ jsxRuntime.jsx(PortalContext.Provider, { value, children });
|
|
3034
3080
|
}
|
|
3035
|
-
const
|
|
3081
|
+
const emptySubscribe$1 = () => () => {
|
|
3082
|
+
}, Root$i = styledComponents.styled.div`
|
|
3036
3083
|
display: block;
|
|
3037
3084
|
width: 0;
|
|
3038
3085
|
height: 0;
|
|
@@ -4287,6 +4334,7 @@ function TooltipDelayGroupProvider(props) {
|
|
|
4287
4334
|
}
|
|
4288
4335
|
const Root$a = styledComponents.styled(Layer)`
|
|
4289
4336
|
pointer-events: none;
|
|
4337
|
+
max-width: ${({ $maxWidth }) => $maxWidth}px;
|
|
4290
4338
|
`, Tooltip = react.forwardRef(function(props, forwardedRef) {
|
|
4291
4339
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
4292
4340
|
const boundaryElementContext = useBoundaryElement(), { layer } = useTheme_v2(), {
|
|
@@ -4306,9 +4354,20 @@ const Root$a = styledComponents.styled(Layer)`
|
|
|
4306
4354
|
zOffset = layer.tooltip.zOffset,
|
|
4307
4355
|
delay,
|
|
4308
4356
|
...restProps
|
|
4309
|
-
} = props, animate = usePrefersReducedMotion() ? !1 : _animate, fallbackPlacements = useArrayProp(fallbackPlacementsProp), ref = react.useRef(null), [referenceElement, setReferenceElement] = react.useState(null), arrowRef = react.useRef(null), rootBoundary = "viewport"
|
|
4357
|
+
} = props, animate = usePrefersReducedMotion() ? !1 : _animate, fallbackPlacements = useArrayProp(fallbackPlacementsProp), ref = react.useRef(null), [referenceElement, setReferenceElement] = react.useState(null), arrowRef = react.useRef(null), rootBoundary = "viewport";
|
|
4310
4358
|
react.useImperativeHandle(forwardedRef, () => ref.current);
|
|
4311
|
-
const portal = usePortal(), portalElement = typeof portalProp == "string" ? ((_c = portal.elements) == null ? void 0 : _c[portalProp]) || null : portal.element,
|
|
4359
|
+
const portal = usePortal(), portalElement = typeof portalProp == "string" ? ((_c = portal.elements) == null ? void 0 : _c[portalProp]) || null : portal.element, documentBodyOffsetWidth = react.useSyncExternalStore(
|
|
4360
|
+
emptySubscribe,
|
|
4361
|
+
() => document.body.offsetWidth,
|
|
4362
|
+
// We don't actually know what the width of the body is during SSR, so we'll just assume it's 800px or larger
|
|
4363
|
+
() => 800
|
|
4364
|
+
), tooltipWidth = react.useMemo(() => {
|
|
4365
|
+
const availableWidths = [
|
|
4366
|
+
...boundaryElement ? [boundaryElement.offsetWidth] : [],
|
|
4367
|
+
(portalElement == null ? void 0 : portalElement.offsetWidth) || documentBodyOffsetWidth
|
|
4368
|
+
];
|
|
4369
|
+
return Math.min(...availableWidths) - DEFAULT_TOOLTIP_PADDING * 2;
|
|
4370
|
+
}, [boundaryElement, documentBodyOffsetWidth, portalElement == null ? void 0 : portalElement.offsetWidth]), middleware = react.useMemo(() => {
|
|
4312
4371
|
const ret = [];
|
|
4313
4372
|
return ret.push(
|
|
4314
4373
|
reactDom$1.flip({
|
|
@@ -4379,7 +4438,15 @@ const Root$a = styledComponents.styled(Layer)`
|
|
|
4379
4438
|
},
|
|
4380
4439
|
[childProp == null ? void 0 : childProp.props, handleIsOpenChange]
|
|
4381
4440
|
);
|
|
4382
|
-
|
|
4441
|
+
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(() => {
|
|
4383
4450
|
disabled && showTooltip && handleIsOpenChange(!1);
|
|
4384
4451
|
}, [disabled, handleIsOpenChange, showTooltip]), react.useEffect(() => {
|
|
4385
4452
|
!content && showTooltip && handleIsOpenChange(!1);
|
|
@@ -4391,13 +4458,7 @@ const Root$a = styledComponents.styled(Layer)`
|
|
|
4391
4458
|
return window.addEventListener("keydown", handleWindowKeyDown), () => {
|
|
4392
4459
|
window.removeEventListener("keydown", handleWindowKeyDown);
|
|
4393
4460
|
};
|
|
4394
|
-
}, [handleIsOpenChange, showTooltip])
|
|
4395
|
-
const availableWidths = [
|
|
4396
|
-
...boundaryElement ? [boundaryElement.offsetWidth] : [],
|
|
4397
|
-
(portalElement == null ? void 0 : portalElement.offsetWidth) || document.body.offsetWidth
|
|
4398
|
-
];
|
|
4399
|
-
setTooltipMaxWidth(Math.min(...availableWidths) - DEFAULT_TOOLTIP_PADDING * 2);
|
|
4400
|
-
}, [boundaryElement, portalElement]);
|
|
4461
|
+
}, [handleIsOpenChange, showTooltip]);
|
|
4401
4462
|
const setArrow = react.useCallback(
|
|
4402
4463
|
(arrowEl) => {
|
|
4403
4464
|
arrowRef.current = arrowEl, update();
|
|
@@ -4438,11 +4499,9 @@ const Root$a = styledComponents.styled(Layer)`
|
|
|
4438
4499
|
"data-ui": "Tooltip",
|
|
4439
4500
|
...restProps,
|
|
4440
4501
|
ref: setFloating,
|
|
4441
|
-
style:
|
|
4442
|
-
...floatingStyles,
|
|
4443
|
-
maxWidth: tooltipMaxWidth > 0 ? `${tooltipMaxWidth}px` : void 0
|
|
4444
|
-
},
|
|
4502
|
+
style: floatingStyles,
|
|
4445
4503
|
zOffset,
|
|
4504
|
+
$maxWidth: tooltipWidth,
|
|
4446
4505
|
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4447
4506
|
TooltipCard,
|
|
4448
4507
|
{
|
|
@@ -4483,24 +4542,8 @@ const Root$a = styledComponents.styled(Layer)`
|
|
|
4483
4542
|
),
|
|
4484
4543
|
child
|
|
4485
4544
|
] });
|
|
4486
|
-
})
|
|
4487
|
-
|
|
4488
|
-
handleIsOpenChange,
|
|
4489
|
-
referenceElement,
|
|
4490
|
-
showTooltip
|
|
4491
|
-
}) {
|
|
4492
|
-
const onMouseMove = useEffectEvent.useEffectEvent((target, teardown) => {
|
|
4493
|
-
referenceElement && (referenceElement === target || target instanceof Node && referenceElement.contains(target) || (handleIsOpenChange(!1), teardown()));
|
|
4494
|
-
});
|
|
4495
|
-
react.useEffect(() => {
|
|
4496
|
-
if (!showTooltip) return;
|
|
4497
|
-
const handleMouseMove = (event) => {
|
|
4498
|
-
onMouseMove(event.target, () => window.removeEventListener("mousemove", handleMouseMove));
|
|
4499
|
-
};
|
|
4500
|
-
return window.addEventListener("mousemove", handleMouseMove), () => window.removeEventListener("mousemove", handleMouseMove);
|
|
4501
|
-
}, [onMouseMove, showTooltip]);
|
|
4502
|
-
}
|
|
4503
|
-
const Root$9 = styledComponents.styled.div`
|
|
4545
|
+
}), emptySubscribe = () => () => {
|
|
4546
|
+
}, Root$9 = styledComponents.styled.div`
|
|
4504
4547
|
line-height: 0;
|
|
4505
4548
|
`, ListBox = styledComponents.styled(Box)`
|
|
4506
4549
|
& > ul {
|
|
@@ -4911,8 +4954,8 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
|
|
|
4911
4954
|
appearance: none;
|
|
4912
4955
|
margin: -4px;
|
|
4913
4956
|
`, Breadcrumbs = react.forwardRef(function(props, ref) {
|
|
4914
|
-
const { children, maxLength, separator, space: spaceRaw = 2, ...restProps } = props, space = useArrayProp(spaceRaw), [open, setOpen] = react.useState(!1),
|
|
4915
|
-
useClickOutside(collapse,
|
|
4957
|
+
const { children, maxLength, separator, space: spaceRaw = 2, ...restProps } = props, space = useArrayProp(spaceRaw), [open, setOpen] = react.useState(!1), [expandElement, setExpandElement] = react.useState(null), [popoverElement, setPopoverElement] = react.useState(null), collapse = react.useCallback(() => setOpen(!1), []), expand = react.useCallback(() => setOpen(!0), []);
|
|
4958
|
+
useClickOutside(collapse, [expandElement, popoverElement]);
|
|
4916
4959
|
const rawItems = react.useMemo(() => react.Children.toArray(children).filter(react.isValidElement), [children]), items = react.useMemo(() => {
|
|
4917
4960
|
const len = rawItems.length;
|
|
4918
4961
|
if (maxLength && len > maxLength) {
|
|
@@ -4927,7 +4970,7 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
|
|
|
4927
4970
|
open,
|
|
4928
4971
|
placement: "top",
|
|
4929
4972
|
portal: !0,
|
|
4930
|
-
ref:
|
|
4973
|
+
ref: setPopoverElement,
|
|
4931
4974
|
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4932
4975
|
ExpandButton,
|
|
4933
4976
|
{
|
|
@@ -4935,7 +4978,7 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
|
|
|
4935
4978
|
mode: "bleed",
|
|
4936
4979
|
onClick: open ? collapse : expand,
|
|
4937
4980
|
padding: 1,
|
|
4938
|
-
ref:
|
|
4981
|
+
ref: setExpandElement,
|
|
4939
4982
|
selected: open,
|
|
4940
4983
|
text: "\u2026"
|
|
4941
4984
|
}
|
|
@@ -5060,8 +5103,8 @@ const Root$7 = styledComponents.styled(Layer)(responsivePaddingStyle, dialogStyl
|
|
|
5060
5103
|
scheme,
|
|
5061
5104
|
shadow: shadowProp,
|
|
5062
5105
|
width: widthProp
|
|
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
|
-
|
|
5106
|
+
} = 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), [rootElement, setRootElement] = react.useState(null), contentRef = react.useRef(null), layer = useLayer(), { isTopLayer } = layer, labelId = `${id}_label`, showCloseButton = !!onClose && hideCloseButton === !1, showHeader = !!header || showCloseButton;
|
|
5107
|
+
react.useImperativeHandle(forwardedRef, () => ref.current), react.useImperativeHandle(
|
|
5065
5108
|
forwardedContentRef,
|
|
5066
5109
|
() => contentRef.current
|
|
5067
5110
|
), react.useEffect(() => {
|
|
@@ -5076,13 +5119,20 @@ const Root$7 = styledComponents.styled(Layer)(responsivePaddingStyle, dialogStyl
|
|
|
5076
5119
|
[boundaryElement, isTopLayer, onClose, portalElement]
|
|
5077
5120
|
)
|
|
5078
5121
|
), useClickOutside(
|
|
5079
|
-
(
|
|
5080
|
-
|
|
5081
|
-
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
|
|
5122
|
+
react.useCallback(
|
|
5123
|
+
(event) => {
|
|
5124
|
+
if (!isTopLayer || !onClickOutside) return;
|
|
5125
|
+
const target = event.target;
|
|
5126
|
+
target && !isTargetWithinScope(boundaryElement, portalElement, target) || onClickOutside();
|
|
5127
|
+
},
|
|
5128
|
+
[boundaryElement, isTopLayer, onClickOutside, portalElement]
|
|
5129
|
+
),
|
|
5130
|
+
[rootElement]
|
|
5131
|
+
);
|
|
5132
|
+
const setRef = react.useCallback((el) => {
|
|
5133
|
+
setRootElement(el), ref.current = el;
|
|
5134
|
+
}, []);
|
|
5135
|
+
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: [
|
|
5086
5136
|
showHeader && /* @__PURE__ */ jsxRuntime.jsx(DialogHeader, { children: /* @__PURE__ */ jsxRuntime.jsxs(Flex, { align: "center", padding: 3, children: [
|
|
5087
5137
|
/* @__PURE__ */ jsxRuntime.jsx(Box, { flex: 1, padding: 2, children: header && /* @__PURE__ */ jsxRuntime.jsx(Text, { id: labelId, size: 1, weight: "semibold", children: header }) }),
|
|
5088
5138
|
showCloseButton && /* @__PURE__ */ jsxRuntime.jsx(Box, { flex: "none", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -5260,13 +5310,13 @@ function _sortElements(rootElement, elements) {
|
|
|
5260
5310
|
elements.sort(_sort);
|
|
5261
5311
|
}
|
|
5262
5312
|
function useMenuController(props) {
|
|
5263
|
-
const { onKeyDown, originElement, shouldFocus
|
|
5313
|
+
const { onKeyDown, originElement, shouldFocus } = props, elementsRef = react.useRef([]), [rootElement, setRootElement] = react.useState(null), [activeIndex, _setActiveIndex] = react.useState(-1), activeIndexRef = react.useRef(activeIndex), activeElement = elementsRef.current[activeIndex] || null, mounted = !!rootElement, setActiveIndex = react.useCallback((nextActiveIndex) => {
|
|
5264
5314
|
_setActiveIndex(nextActiveIndex), activeIndexRef.current = nextActiveIndex;
|
|
5265
5315
|
}, []), mount = react.useCallback(
|
|
5266
5316
|
(element, selected) => {
|
|
5267
5317
|
if (!element) return () => {
|
|
5268
5318
|
};
|
|
5269
|
-
if (elementsRef.current.indexOf(element) === -1 && (elementsRef.current.push(element), _sortElements(
|
|
5319
|
+
if (elementsRef.current.indexOf(element) === -1 && (elementsRef.current.push(element), _sortElements(rootElement, elementsRef.current)), selected) {
|
|
5270
5320
|
const selectedIndex = elementsRef.current.indexOf(element);
|
|
5271
5321
|
setActiveIndex(selectedIndex);
|
|
5272
5322
|
}
|
|
@@ -5275,7 +5325,7 @@ function useMenuController(props) {
|
|
|
5275
5325
|
idx > -1 && elementsRef.current.splice(idx, 1);
|
|
5276
5326
|
};
|
|
5277
5327
|
},
|
|
5278
|
-
[
|
|
5328
|
+
[rootElement, setActiveIndex]
|
|
5279
5329
|
), handleKeyDown = react.useCallback(
|
|
5280
5330
|
(event) => {
|
|
5281
5331
|
if (event.key === "Tab") {
|
|
@@ -5330,13 +5380,13 @@ function useMenuController(props) {
|
|
|
5330
5380
|
},
|
|
5331
5381
|
[setActiveIndex]
|
|
5332
5382
|
), handleItemMouseLeave = react.useCallback(() => {
|
|
5333
|
-
|
|
5334
|
-
|
|
5335
|
-
}, [rootElementRef, setActiveIndex]);
|
|
5383
|
+
setActiveIndex(-2), rootElement == null || rootElement.focus();
|
|
5384
|
+
}, [setActiveIndex, rootElement]);
|
|
5336
5385
|
return react.useEffect(() => {
|
|
5337
5386
|
if (!mounted) return;
|
|
5338
5387
|
const rafId = window.requestAnimationFrame(() => {
|
|
5339
|
-
|
|
5388
|
+
const _activeIndex = activeIndexRef.current;
|
|
5389
|
+
if (_activeIndex === -1) {
|
|
5340
5390
|
if (shouldFocus === "first") {
|
|
5341
5391
|
const el = _getFocusableElements(elementsRef.current)[0];
|
|
5342
5392
|
if (el) {
|
|
@@ -5353,7 +5403,7 @@ function useMenuController(props) {
|
|
|
5353
5403
|
}
|
|
5354
5404
|
return;
|
|
5355
5405
|
}
|
|
5356
|
-
const element = elementsRef.current[
|
|
5406
|
+
const element = elementsRef.current[_activeIndex] || null;
|
|
5357
5407
|
element == null || element.focus();
|
|
5358
5408
|
});
|
|
5359
5409
|
return () => {
|
|
@@ -5365,7 +5415,9 @@ function useMenuController(props) {
|
|
|
5365
5415
|
handleItemMouseEnter,
|
|
5366
5416
|
handleItemMouseLeave,
|
|
5367
5417
|
handleKeyDown,
|
|
5368
|
-
mount
|
|
5418
|
+
mount,
|
|
5419
|
+
rootElement,
|
|
5420
|
+
setRootElement
|
|
5369
5421
|
};
|
|
5370
5422
|
}
|
|
5371
5423
|
const Root$5 = styledComponents.styled(Box)`
|
|
@@ -5397,18 +5449,23 @@ const Root$5 = styledComponents.styled(Box)`
|
|
|
5397
5449
|
handleItemMouseEnter,
|
|
5398
5450
|
handleItemMouseLeave,
|
|
5399
5451
|
handleKeyDown,
|
|
5400
|
-
mount
|
|
5401
|
-
|
|
5452
|
+
mount,
|
|
5453
|
+
rootElement,
|
|
5454
|
+
setRootElement
|
|
5455
|
+
} = useMenuController({ onKeyDown, originElement, shouldFocus }), handleRefChange = react.useCallback(
|
|
5402
5456
|
(el) => {
|
|
5403
|
-
|
|
5457
|
+
setRootElement(el), ref.current = el;
|
|
5404
5458
|
},
|
|
5405
|
-
[
|
|
5459
|
+
[setRootElement]
|
|
5406
5460
|
);
|
|
5407
5461
|
react.useEffect(() => {
|
|
5408
5462
|
onItemSelect && onItemSelect(activeIndex);
|
|
5409
5463
|
}, [activeIndex, onItemSelect]), useClickOutside(
|
|
5410
|
-
(
|
|
5411
|
-
|
|
5464
|
+
react.useCallback(
|
|
5465
|
+
(event) => isTopLayer && onClickOutside && onClickOutside(event),
|
|
5466
|
+
[isTopLayer, onClickOutside]
|
|
5467
|
+
),
|
|
5468
|
+
[rootElement]
|
|
5412
5469
|
), useGlobalKeyDown(
|
|
5413
5470
|
react.useCallback(
|
|
5414
5471
|
(event) => {
|
|
@@ -5416,7 +5473,10 @@ const Root$5 = styledComponents.styled(Box)`
|
|
|
5416
5473
|
},
|
|
5417
5474
|
[isTopLayer, onEscape]
|
|
5418
5475
|
)
|
|
5419
|
-
)
|
|
5476
|
+
), react.useEffect(() => {
|
|
5477
|
+
if (!(!rootElement || !registerElement))
|
|
5478
|
+
return registerElement(rootElement);
|
|
5479
|
+
}, [registerElement, rootElement]);
|
|
5420
5480
|
const value = react.useMemo(
|
|
5421
5481
|
() => ({
|
|
5422
5482
|
version: 0,
|
|
@@ -6092,7 +6152,7 @@ const CustomInline = styledComponents.styled(Inline)`
|
|
|
6092
6152
|
}
|
|
6093
6153
|
100% {
|
|
6094
6154
|
width: 100%;
|
|
6095
|
-
}
|
|
6155
|
+
}
|
|
6096
6156
|
`, LOADING_BAR_HEIGHT = 2;
|
|
6097
6157
|
function rootStyles(props) {
|
|
6098
6158
|
const { color } = getTheme_v2.getTheme_v2(props.theme), loadingBarColor = color.button.default[props.tone].enabled.bg;
|
|
@@ -6178,7 +6238,15 @@ function Toast(props) {
|
|
|
6178
6238
|
}
|
|
6179
6239
|
);
|
|
6180
6240
|
}
|
|
6181
|
-
|
|
6241
|
+
function useMounted() {
|
|
6242
|
+
return react.useSyncExternalStore(
|
|
6243
|
+
subscribe,
|
|
6244
|
+
() => !0,
|
|
6245
|
+
() => !1
|
|
6246
|
+
);
|
|
6247
|
+
}
|
|
6248
|
+
const subscribe = () => () => {
|
|
6249
|
+
}, key$1 = Symbol.for("@sanity/ui/context/toast"), ToastContext = createGlobalScopedContext(key$1, null), Root$1 = styledComponents.styled(Layer)`
|
|
6182
6250
|
position: fixed;
|
|
6183
6251
|
top: 0;
|
|
6184
6252
|
left: 0;
|
|
@@ -6789,7 +6857,6 @@ exports.useElementSize = useElementSize;
|
|
|
6789
6857
|
exports.useForwardedRef = useForwardedRef;
|
|
6790
6858
|
exports.useGlobalKeyDown = useGlobalKeyDown;
|
|
6791
6859
|
exports.useLayer = useLayer;
|
|
6792
|
-
exports.useMatchMedia = useMatchMedia;
|
|
6793
6860
|
exports.useMediaIndex = useMediaIndex;
|
|
6794
6861
|
exports.usePortal = usePortal;
|
|
6795
6862
|
exports.usePrefersDark = usePrefersDark;
|