@sanity/ui 2.8.5 → 2.8.6
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.esm.js +33 -50
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +33 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -50
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/core/components/menu/menu.tsx +20 -20
- package/src/core/components/menu/menuButton.tsx +1 -5
- package/src/core/components/menu/menuGroup.tsx +17 -17
- package/src/core/components/menu/useMenuController.ts +13 -23
- package/src/core/components/toast/styles.ts +1 -1
- package/src/core/hooks/useClickOutsideEvent.ts +2 -4
package/dist/index.js
CHANGED
|
@@ -173,10 +173,10 @@ function useClickOutsideEvent(listener, elementsArg = () => EMPTY_ARRAY, boundar
|
|
|
173
173
|
const target = evt.target;
|
|
174
174
|
if (!(target instanceof Node))
|
|
175
175
|
return;
|
|
176
|
-
const resolvedBoundaryElement =
|
|
176
|
+
const resolvedBoundaryElement = boundaryElement == null ? void 0 : boundaryElement();
|
|
177
177
|
if (resolvedBoundaryElement && !resolvedBoundaryElement.contains(target))
|
|
178
178
|
return;
|
|
179
|
-
const elements =
|
|
179
|
+
const elements = elementsArg().flat();
|
|
180
180
|
for (const el of elements)
|
|
181
181
|
if (el && (target === el || el.contains(target)))
|
|
182
182
|
return;
|
|
@@ -5329,13 +5329,13 @@ function _sortElements(rootElement, elements) {
|
|
|
5329
5329
|
elements.sort(_sort);
|
|
5330
5330
|
}
|
|
5331
5331
|
function useMenuController(props) {
|
|
5332
|
-
const { onKeyDown, originElement, shouldFocus } = props, elementsRef = react.useRef([]), [
|
|
5332
|
+
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) => {
|
|
5333
5333
|
_setActiveIndex(nextActiveIndex), activeIndexRef.current = nextActiveIndex;
|
|
5334
5334
|
}, []), mount = react.useCallback(
|
|
5335
5335
|
(element, selected) => {
|
|
5336
5336
|
if (!element) return () => {
|
|
5337
5337
|
};
|
|
5338
|
-
if (elementsRef.current.indexOf(element) === -1 && (elementsRef.current.push(element), _sortElements(
|
|
5338
|
+
if (elementsRef.current.indexOf(element) === -1 && (elementsRef.current.push(element), _sortElements(rootElementRef.current, elementsRef.current)), selected) {
|
|
5339
5339
|
const selectedIndex = elementsRef.current.indexOf(element);
|
|
5340
5340
|
setActiveIndex(selectedIndex);
|
|
5341
5341
|
}
|
|
@@ -5344,7 +5344,7 @@ function useMenuController(props) {
|
|
|
5344
5344
|
idx > -1 && elementsRef.current.splice(idx, 1);
|
|
5345
5345
|
};
|
|
5346
5346
|
},
|
|
5347
|
-
[
|
|
5347
|
+
[rootElementRef, setActiveIndex]
|
|
5348
5348
|
), handleKeyDown = react.useCallback(
|
|
5349
5349
|
(event) => {
|
|
5350
5350
|
if (event.key === "Tab") {
|
|
@@ -5399,44 +5399,40 @@ function useMenuController(props) {
|
|
|
5399
5399
|
},
|
|
5400
5400
|
[setActiveIndex]
|
|
5401
5401
|
), handleItemMouseLeave = react.useCallback(() => {
|
|
5402
|
-
|
|
5403
|
-
|
|
5402
|
+
var _a;
|
|
5403
|
+
setActiveIndex(-2), (_a = rootElementRef.current) == null || _a.focus();
|
|
5404
|
+
}, [rootElementRef, setActiveIndex]);
|
|
5404
5405
|
return react.useEffect(() => {
|
|
5405
5406
|
if (!mounted) return;
|
|
5406
|
-
const rafId =
|
|
5407
|
-
|
|
5408
|
-
if (_activeIndex === -1) {
|
|
5407
|
+
const rafId = requestAnimationFrame(() => {
|
|
5408
|
+
if (activeIndex === -1) {
|
|
5409
5409
|
if (shouldFocus === "first") {
|
|
5410
5410
|
const el = _getFocusableElements(elementsRef.current)[0];
|
|
5411
5411
|
if (el) {
|
|
5412
5412
|
const currentIndex = elementsRef.current.indexOf(el);
|
|
5413
|
-
setActiveIndex(currentIndex)
|
|
5413
|
+
setActiveIndex(currentIndex);
|
|
5414
5414
|
}
|
|
5415
5415
|
}
|
|
5416
5416
|
if (shouldFocus === "last") {
|
|
5417
5417
|
const focusableElements = _getFocusableElements(elementsRef.current), el = focusableElements[focusableElements.length - 1];
|
|
5418
5418
|
if (el) {
|
|
5419
5419
|
const currentIndex = elementsRef.current.indexOf(el);
|
|
5420
|
-
setActiveIndex(currentIndex)
|
|
5420
|
+
setActiveIndex(currentIndex);
|
|
5421
5421
|
}
|
|
5422
5422
|
}
|
|
5423
5423
|
return;
|
|
5424
5424
|
}
|
|
5425
|
-
const element = elementsRef.current[
|
|
5425
|
+
const element = elementsRef.current[activeIndex] || null;
|
|
5426
5426
|
element == null || element.focus();
|
|
5427
5427
|
});
|
|
5428
|
-
return () =>
|
|
5429
|
-
window.cancelAnimationFrame(rafId);
|
|
5430
|
-
};
|
|
5428
|
+
return () => cancelAnimationFrame(rafId);
|
|
5431
5429
|
}, [activeIndex, mounted, setActiveIndex, shouldFocus]), {
|
|
5432
5430
|
activeElement,
|
|
5433
5431
|
activeIndex,
|
|
5434
5432
|
handleItemMouseEnter,
|
|
5435
5433
|
handleItemMouseLeave,
|
|
5436
5434
|
handleKeyDown,
|
|
5437
|
-
mount
|
|
5438
|
-
rootElement,
|
|
5439
|
-
setRootElement
|
|
5435
|
+
mount
|
|
5440
5436
|
};
|
|
5441
5437
|
}
|
|
5442
5438
|
const Root$5 = styledComponents.styled(Box)`
|
|
@@ -5468,34 +5464,23 @@ const Root$5 = styledComponents.styled(Box)`
|
|
|
5468
5464
|
handleItemMouseEnter,
|
|
5469
5465
|
handleItemMouseLeave,
|
|
5470
5466
|
handleKeyDown,
|
|
5471
|
-
mount
|
|
5472
|
-
|
|
5473
|
-
setRootElement
|
|
5474
|
-
} = useMenuController({ onKeyDown, originElement, shouldFocus }), handleRefChange = react.useCallback(
|
|
5467
|
+
mount
|
|
5468
|
+
} = useMenuController({ onKeyDown, originElement, shouldFocus, rootElementRef: ref }), unregisterElementRef = react.useRef(null), handleRefChange = react.useCallback(
|
|
5475
5469
|
(el) => {
|
|
5476
|
-
|
|
5470
|
+
unregisterElementRef.current && (unregisterElementRef.current(), unregisterElementRef.current = null), ref.current = el, ref.current && registerElement && (unregisterElementRef.current = registerElement(ref.current));
|
|
5477
5471
|
},
|
|
5478
|
-
[
|
|
5472
|
+
[registerElement]
|
|
5479
5473
|
);
|
|
5480
5474
|
react.useEffect(() => {
|
|
5481
5475
|
onItemSelect && onItemSelect(activeIndex);
|
|
5482
|
-
}, [activeIndex, onItemSelect]),
|
|
5483
|
-
react.useCallback(
|
|
5484
|
-
(event) => isTopLayer && onClickOutside && onClickOutside(event),
|
|
5485
|
-
[isTopLayer, onClickOutside]
|
|
5486
|
-
),
|
|
5487
|
-
[rootElement]
|
|
5488
|
-
), useGlobalKeyDown(
|
|
5476
|
+
}, [activeIndex, onItemSelect]), useClickOutsideEvent(isTopLayer && onClickOutside, () => [ref.current]), useGlobalKeyDown(
|
|
5489
5477
|
react.useCallback(
|
|
5490
5478
|
(event) => {
|
|
5491
5479
|
isTopLayer && event.key === "Escape" && (event.stopPropagation(), onEscape && onEscape());
|
|
5492
5480
|
},
|
|
5493
5481
|
[isTopLayer, onEscape]
|
|
5494
5482
|
)
|
|
5495
|
-
)
|
|
5496
|
-
if (!(!rootElement || !registerElement))
|
|
5497
|
-
return registerElement(rootElement);
|
|
5498
|
-
}, [registerElement, rootElement]);
|
|
5483
|
+
);
|
|
5499
5484
|
const value = react.useMemo(
|
|
5500
5485
|
() => ({
|
|
5501
5486
|
version: 0,
|
|
@@ -5602,9 +5587,7 @@ const Root$5 = styledComponents.styled(Box)`
|
|
|
5602
5587
|
[menuElements]
|
|
5603
5588
|
), handleItemClick = react.useCallback(() => {
|
|
5604
5589
|
setOpen(!1), !disableRestoreFocusOnClose && buttonElement && buttonElement.focus();
|
|
5605
|
-
}, [buttonElement, disableRestoreFocusOnClose]), registerElement = react.useCallback((el) => (setChildMenuElements((els) => els.concat([el])), () =>
|
|
5606
|
-
setChildMenuElements((els) => els.filter((_el) => _el !== el));
|
|
5607
|
-
}), []), menuProps = react.useMemo(
|
|
5590
|
+
}, [buttonElement, disableRestoreFocusOnClose]), registerElement = react.useCallback((el) => (setChildMenuElements((els) => els.concat([el])), () => setChildMenuElements((els) => els.filter((_el) => _el !== el))), []), menuProps = react.useMemo(
|
|
5608
5591
|
() => ({
|
|
5609
5592
|
"aria-labelledby": id,
|
|
5610
5593
|
onBlurCapture: handleBlur,
|
|
@@ -5808,7 +5791,7 @@ function MenuGroup(props) {
|
|
|
5808
5791
|
onItemClick,
|
|
5809
5792
|
onItemMouseEnter = menu.onMouseEnter,
|
|
5810
5793
|
registerElement
|
|
5811
|
-
} = menu, [rootElement, setRootElement] = react.useState(null), [open, setOpen] = react.useState(!1),
|
|
5794
|
+
} = menu, [rootElement, setRootElement] = react.useState(null), [open, setOpen] = react.useState(!1), [shouldFocus, setShouldFocus] = react.useState(null), active = !!activeElement && activeElement === rootElement, [withinMenu, setWithinMenu] = react.useState(!1), handleMouseEnter = react.useCallback(
|
|
5812
5795
|
(event) => {
|
|
5813
5796
|
setWithinMenu(!1), onItemMouseEnter(event), setOpen(!0);
|
|
5814
5797
|
},
|
|
@@ -5822,19 +5805,21 @@ function MenuGroup(props) {
|
|
|
5822
5805
|
[rootElement]
|
|
5823
5806
|
), handleClick = react.useCallback(
|
|
5824
5807
|
(event) => {
|
|
5825
|
-
onClick
|
|
5826
|
-
shouldFocusRef.current = null;
|
|
5827
|
-
});
|
|
5808
|
+
onClick == null || onClick(event), setShouldFocus("first"), setOpen(!0);
|
|
5828
5809
|
},
|
|
5829
5810
|
[onClick]
|
|
5830
5811
|
), handleChildItemClick = react.useCallback(() => {
|
|
5831
|
-
setOpen(!1), onItemClick
|
|
5812
|
+
setOpen(!1), onItemClick == null || onItemClick();
|
|
5832
5813
|
}, [onItemClick]), handleMenuMouseEnter = react.useCallback(() => setWithinMenu(!0), []);
|
|
5833
5814
|
react.useEffect(() => mount(rootElement), [mount, rootElement]), react.useEffect(() => {
|
|
5834
5815
|
active || setOpen(!1);
|
|
5835
5816
|
}, [active]), react.useEffect(() => {
|
|
5836
5817
|
open || setWithinMenu(!1);
|
|
5837
|
-
}, [open])
|
|
5818
|
+
}, [open]), react.useEffect(() => {
|
|
5819
|
+
if (!shouldFocus) return;
|
|
5820
|
+
const rafId = requestAnimationFrame(() => setShouldFocus(null));
|
|
5821
|
+
return () => cancelAnimationFrame(rafId);
|
|
5822
|
+
}, [shouldFocus]);
|
|
5838
5823
|
const childMenu = /* @__PURE__ */ jsxRuntime.jsx(
|
|
5839
5824
|
Menu,
|
|
5840
5825
|
{
|
|
@@ -5844,15 +5829,13 @@ function MenuGroup(props) {
|
|
|
5844
5829
|
onKeyDown: handleMenuKeyDown,
|
|
5845
5830
|
onMouseEnter: handleMenuMouseEnter,
|
|
5846
5831
|
registerElement,
|
|
5847
|
-
shouldFocus
|
|
5832
|
+
shouldFocus,
|
|
5848
5833
|
children
|
|
5849
5834
|
}
|
|
5850
5835
|
), handleKeyDown = react.useCallback((event) => {
|
|
5851
5836
|
const target = event.currentTarget;
|
|
5852
5837
|
if (document.activeElement === target && event.key === "ArrowRight") {
|
|
5853
|
-
|
|
5854
|
-
shouldFocusRef.current = null;
|
|
5855
|
-
});
|
|
5838
|
+
setShouldFocus("first"), setOpen(!0), setWithinMenu(!0);
|
|
5856
5839
|
return;
|
|
5857
5840
|
}
|
|
5858
5841
|
}, []);
|
|
@@ -6171,7 +6154,7 @@ const CustomInline = styledComponents.styled(Inline)`
|
|
|
6171
6154
|
}
|
|
6172
6155
|
100% {
|
|
6173
6156
|
width: 100%;
|
|
6174
|
-
}
|
|
6157
|
+
}
|
|
6175
6158
|
`, LOADING_BAR_HEIGHT = 2;
|
|
6176
6159
|
function rootStyles(props) {
|
|
6177
6160
|
const { color } = getTheme_v2.getTheme_v2(props.theme), loadingBarColor = color.button.default[props.tone].enabled.bg;
|