Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@radix-ui/react-menu

Package Overview
Dependencies
Maintainers
8
Versions
256
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@radix-ui/react-menu - npm Package Compare versions

Comparing version 0.0.18 to 0.0.19

88

dist/index.d.ts

@@ -8,11 +8,20 @@ import * as React from "react";

import * as Polymorphic from "@radix-ui/react-polymorphic";
type FocusScopeProps = React.ComponentProps<typeof FocusScope>;
type DismissableLayerProps = React.ComponentProps<typeof DismissableLayer>;
type RovingFocusGroupProps = React.ComponentProps<typeof RovingFocusGroup>;
type Direction = 'ltr' | 'rtl';
type MenuOwnProps = {
open?: boolean;
onOpenChange?(open: boolean): void;
dir?: Direction;
};
export const Menu: React.FC<MenuOwnProps>;
type MenuContentOwnProps = Polymorphic.Merge<Polymorphic.OwnProps<typeof MenuContentImpl>, {
type MenuSubOwnProps = {
open?: boolean;
onOpenChange?(open: boolean): void;
};
export const MenuSub: React.FC<MenuSubOwnProps>;
/**
* We purposefully don't union MenuRootContent and MenuSubContent props here because
* they have conflicting prop types. We agreed that we would allow MenuSubContent to
* accept props that it would just ignore.
*/
type MenuContentOwnProps = Polymorphic.Merge<Polymorphic.OwnProps<typeof MenuRootContent>, {
/**

@@ -24,5 +33,15 @@ * Used to force mounting when more control is needed. Useful when

}>;
export type MenuContentPrimitive = Polymorphic.ForwardRefComponent<Polymorphic.IntrinsicElement<typeof MenuContentImpl>, MenuContentOwnProps>;
export type MenuContentPrimitive = Polymorphic.ForwardRefComponent<Polymorphic.IntrinsicElement<typeof MenuRootContent>, MenuContentOwnProps>;
export const MenuContent: MenuContentPrimitive;
type MenuContentImplOwnProps = Polymorphic.Merge<Polymorphic.OwnProps<typeof PopperPrimitive.Content>, {
type MenuRootContentOwnProps = Omit<Polymorphic.OwnProps<typeof MenuContentImpl>, keyof MenuContentImplPrivateProps>;
type MenuRootContentPrimitive = Polymorphic.ForwardRefComponent<Polymorphic.IntrinsicElement<typeof MenuContentImpl>, MenuRootContentOwnProps>;
declare const MenuRootContent: MenuRootContentPrimitive;
type FocusScopeOwnProps = Polymorphic.OwnProps<typeof FocusScope>;
type DismissableLayerOwnProps = Polymorphic.OwnProps<typeof DismissableLayer>;
type RovingFocusGroupOwnProps = Polymorphic.OwnProps<typeof RovingFocusGroup>;
type MenuContentImplPrivateProps = {
onOpenAutoFocus?: FocusScopeOwnProps['onMountAutoFocus'];
onDismiss?: DismissableLayerOwnProps['onDismiss'];
};
type MenuContentImplOwnProps = Polymorphic.Merge<Polymorphic.OwnProps<typeof PopperPrimitive.Content>, Omit<DismissableLayerOwnProps, 'onDismiss'> & MenuContentImplPrivateProps & {
/**

@@ -32,41 +51,9 @@ * Whether focus should be trapped within the `MenuContent`

*/
trapFocus?: FocusScopeProps['trapped'];
trapFocus?: FocusScopeOwnProps['trapped'];
/**
* Event handler called when auto-focusing on open.
* Can be prevented.
*/
onOpenAutoFocus?: FocusScopeProps['onMountAutoFocus'];
/**
* Event handler called when auto-focusing on close.
* Can be prevented.
*/
onCloseAutoFocus?: FocusScopeProps['onUnmountAutoFocus'];
onCloseAutoFocus?: FocusScopeOwnProps['onUnmountAutoFocus'];
/**
* When `true`, hover/focus/click interactions will be disabled on elements outside the `MenuContent`.
* Users will need to click twice on outside elements to interact with them:
* Once to close the `MenuContent`, and again to trigger the element.
*/
disableOutsidePointerEvents?: DismissableLayerProps['disableOutsidePointerEvents'];
/**
* Event handler called when the escape key is down.
* Can be prevented.
*/
onEscapeKeyDown?: DismissableLayerProps['onEscapeKeyDown'];
/**
* Event handler called when the a pointer event happens outside of the `MenuContent`.
* Can be prevented.
*/
onPointerDownOutside?: DismissableLayerProps['onPointerDownOutside'];
/**
* Event handler called when the focus moves outside of the `MenuContent`.
* Can be prevented.
*/
onFocusOutside?: DismissableLayerProps['onFocusOutside'];
/**
* Event handler called when an interaction happens outside the `MenuContent`.
* Specifically, when a pointer event happens outside of the `MenuContent` or focus moves outside of it.
* Can be prevented.
*/
onInteractOutside?: DismissableLayerProps['onInteractOutside'];
/**
* Whether scrolling outside the `MenuContent` should be prevented

@@ -80,3 +67,3 @@ * (default: `false`)

*/
dir?: RovingFocusGroupProps['dir'];
dir?: RovingFocusGroupOwnProps['dir'];
/**

@@ -86,3 +73,3 @@ * Whether keyboard navigation should loop around

*/
loop?: RovingFocusGroupProps['loop'];
loop?: RovingFocusGroupOwnProps['loop'];
/**

@@ -97,9 +84,16 @@ * Whether the `MenuContent` should render in a `Portal`

declare const ITEM_DEFAULT_TAG = "div";
type MenuItemOwnProps = Polymorphic.Merge<Omit<Polymorphic.OwnProps<typeof RovingFocusItem>, 'focusable' | 'active'>, {
type MenuItemOwnProps = Polymorphic.Merge<Polymorphic.OwnProps<typeof MenuItemImpl>, {
onSelect?: (event: Event) => void;
}>;
export type MenuItemPrimitive = Polymorphic.ForwardRefComponent<Polymorphic.IntrinsicElement<typeof MenuItemImpl>, MenuItemOwnProps>;
export const MenuItem: MenuItemPrimitive;
type MenuSubTriggerOwnProps = Polymorphic.OwnProps<typeof MenuItemImpl>;
export type MenuSubTriggerPrimitive = Polymorphic.ForwardRefComponent<Polymorphic.IntrinsicElement<typeof MenuItemImpl>, MenuSubTriggerOwnProps>;
export const MenuSubTrigger: MenuSubTriggerPrimitive;
type MenuItemImplOwnProps = Polymorphic.Merge<Omit<Polymorphic.OwnProps<typeof RovingFocusItem>, 'focusable' | 'active'>, {
disabled?: boolean;
textValue?: string;
onSelect?: (event: Event) => void;
}>;
export type MenuItemPrimitive = Polymorphic.ForwardRefComponent<typeof ITEM_DEFAULT_TAG, MenuItemOwnProps>;
export const MenuItem: MenuItemPrimitive;
type MenuItemImplPrimitive = Polymorphic.ForwardRefComponent<typeof ITEM_DEFAULT_TAG, MenuItemImplOwnProps>;
declare const MenuItemImpl: MenuItemImplPrimitive;
type MenuCheckboxItemOwnProps = Polymorphic.Merge<Polymorphic.OwnProps<typeof MenuItem>, {

@@ -138,3 +132,5 @@ checked?: boolean;

export const Root: React.FC<MenuOwnProps>;
export const Sub: React.FC<MenuSubOwnProps>;
export const Anchor: import("@radix-ui/react-primitive").ExtendedPrimitive<PopperPrimitive.PopperAnchorPrimitive, "div">;
export const SubTrigger: MenuSubTriggerPrimitive;
export const Content: MenuContentPrimitive;

@@ -141,0 +137,0 @@ export const Group: import("@radix-ui/react-primitive").ExtendedPrimitive<import("@radix-ui/react-primitive").PrimitivePrimitive, "div">;

@@ -1,2 +0,2 @@

var e,t=require("@radix-ui/react-focus-guards").useFocusGuards,r=require("@radix-ui/react-use-callback-ref").useCallbackRef,n=require("@radix-ui/react-slot").Slot,o=require("@radix-ui/react-roving-focus"),u=o.RovingFocusGroup,a=o.RovingFocusItem,c=require("@radix-ui/react-portal").Portal,s=k({},require("@radix-ui/react-popper")),l=require("@radix-ui/react-primitive"),i=l.Primitive,d=l.extendPrimitive,p=require("@radix-ui/react-presence").Presence,f=require("@radix-ui/react-focus-scope").FocusScope,m=require("@radix-ui/react-dismissable-layer").DismissableLayer,v=require("@radix-ui/react-context").createContext,x=require("@radix-ui/react-compose-refs"),h=x.composeRefs,C=x.useComposedRefs,y=require("@radix-ui/react-collection").createCollection,E=require("@radix-ui/primitive").composeEventHandlers,M=require("aria-hidden").hideOthers,w=require("react-remove-scroll").RemoveScroll,b=k({},require("react")),D=(e=require("@babel/runtime/helpers/extends"))&&e.__esModule?e.default:e;function k(e,t){return Object.keys(t).forEach((function(r){"default"!==r&&"__esModule"!==r&&Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[r]}})})),e}function g(){const e=b.useRef(0),t=b.useRef(""),r=b.useCallback((n=>{t.current=n,window.clearTimeout(e.current),e.current=window.setTimeout((()=>r("")),1e3)}),[]);return{onKeyDownCapture:e=>{if(1===e.key.length&&!(e.ctrlKey||e.altKey||e.metaKey)){const n=e.currentTarget;r(t.current+e.key)," "!==e.key||t.current.startsWith(" ")||e.stopPropagation();const o=document.activeElement,u=o?P(o):void 0,a=function(e,t,r){const n=t.length>1&&Array.from(t).every((e=>e===t[0]))?t[0]:t,o=r?e.indexOf(r):-1;let u=(a=e,c=Math.max(o,0),a.map(((e,t)=>a[(c+t)%a.length])));var a,c;1===n.length&&(u=u.filter((e=>e!==r)));const s=u.find((e=>e.toLowerCase().startsWith(n.toLowerCase())));return s!==r?s:void 0}(Array.from(n.querySelectorAll(`[${F}]`)).map(P),t.current,u),c=n.querySelector(`[${F}="${a}"]`);c&&setTimeout((()=>c.focus()))}}}}const P=e=>{var t;return null!==(t=e.getAttribute(F))&&void 0!==t?t:""},F="data-radix-menu-typeahead-item";const S=["ArrowUp","PageDown","End"],R=["ArrowDown","PageUp","Home",...S],[I,q]=v("Menu"),A=e=>{const{open:t=!1,children:n,onOpenChange:o}=e,u=r(o);/*#__PURE__*/return b.createElement(s.Root,null,/*#__PURE__*/b.createElement(I,{open:t,onOpenChange:u},n))};exports.Menu=A;const[O,K,L]=y(),[T,G]=v("MenuContent"),V=/*#__PURE__*/b.forwardRef(((e,t)=>{const{forceMount:r,...n}=e,o=q("MenuContent");/*#__PURE__*/return b.createElement(p,{present:r||o.open},/*#__PURE__*/b.createElement(O,null,/*#__PURE__*/b.createElement(N,D({"data-state":(u=o.open,u?"open":"closed")},n,{ref:t}))));var u}));exports.MenuContent=V;const N=/*#__PURE__*/b.forwardRef(((e,r)=>{const{dir:o="ltr",loop:a=!1,trapFocus:l,onOpenAutoFocus:i,onCloseAutoFocus:d,disableOutsidePointerEvents:p,onEscapeKeyDown:v,onPointerDownOutside:x,onFocusOutside:C,onInteractOutside:y,disableOutsideScroll:k,portalled:P,...F}=e,I=q("MenuContent"),A=b.useRef(null),O=g(),{getItems:K}=L(),[G,V]=b.useState(null),[N,U]=b.useState(!1),_=P?c:b.Fragment,B=k?w:b.Fragment;return t(),b.useEffect((()=>{const e=A.current;if(e)return M(e)}),[]),/*#__PURE__*/b.createElement(_,null,/*#__PURE__*/b.createElement(B,null,/*#__PURE__*/b.createElement(T,{onItemLeave:b.useCallback((()=>{var e;null===(e=A.current)||void 0===e||e.focus(),V(null)}),[])},/*#__PURE__*/b.createElement(f,{trapped:!N&&(l&&I.open),onMountAutoFocus:i,onUnmountAutoFocus:e=>{N?e.preventDefault():null==d||d(e)}},(e=>/*#__PURE__*/b.createElement(m,{disableOutsidePointerEvents:p,onEscapeKeyDown:v,onPointerDownOutside:E(x,(e=>{const t=0===e.button&&!1===e.ctrlKey;U(!p&&t),e.defaultPrevented&&U(!1)}),{checkForDefaultPrevented:!1}),onFocusOutside:E(C,(e=>{l&&e.preventDefault()}),{checkForDefaultPrevented:!1}),onInteractOutside:y,onDismiss:()=>I.onOpenChange(!1)},(t=>/*#__PURE__*/b.createElement(u,{as:n,dir:o,orientation:"vertical",loop:a,currentTabStopId:G,onCurrentTabStopIdChange:V,onEntryFocus:e=>e.preventDefault()},/*#__PURE__*/b.createElement(s.Content,D({role:"menu"},e,F,{ref:h(r,A,e.ref),style:{...t.style,outline:"none",...F.style},onBlurCapture:E(F.onBlurCapture,t.onBlurCapture,{checkForDefaultPrevented:!1}),onFocusCapture:E(F.onFocusCapture,t.onFocusCapture,{checkForDefaultPrevented:!1}),onMouseDownCapture:E(F.onMouseDownCapture,t.onMouseDownCapture,{checkForDefaultPrevented:!1}),onTouchStartCapture:E(F.onTouchStartCapture,t.onTouchStartCapture,{checkForDefaultPrevented:!1}),onKeyDownCapture:E(F.onKeyDownCapture,O.onKeyDownCapture),onKeyDown:E(F.onKeyDown,E(e.onKeyDown,(e=>{const t=A.current;if(e.target!==t)return;if(!R.includes(e.key))return;e.preventDefault();const r=K().filter((e=>!e.disabled)).map((e=>e.ref.current));S.includes(e.key)&&r.reverse(),function(e){const t=document.activeElement;for(const r of e){if(r===t)return;if(r.focus(),document.activeElement!==t)return}}(r)})))}))))))))))})),U="div",_=/*#__PURE__*/b.forwardRef(((e,t)=>{const{as:r=U,disabled:n=!1,textValue:o,onSelect:u,...c}=e,s=b.useRef(null),l=C(t,s),i=q("MenuItem"),d=G("MenuItem"),[p,f]=b.useState("");b.useEffect((()=>{const e=s.current;var t;e&&f((null!==(t=e.textContent)&&void 0!==t?t:"").trim())}),[c.children]);const m=function({textValue:e,disabled:t}){return{[F]:t?void 0:e}}({textValue:null!=o?o:p,disabled:n}),v=()=>{const e=s.current;if(!n&&e){var t;const r=new Event("menu.itemSelect",{bubbles:!0,cancelable:!0});if(e.dispatchEvent(r),r.defaultPrevented)return;null===(t=i.onOpenChange)||void 0===t||t.call(i,!1)}};return b.useEffect((()=>{const e=s.current;if(e){const t=e=>null==u?void 0:u(e);return e.addEventListener("menu.itemSelect",t),()=>e.removeEventListener("menu.itemSelect",t)}}),[u]),/*#__PURE__*/b.createElement(K,{disabled:n},/*#__PURE__*/b.createElement(a,D({role:"menuitem","aria-disabled":n||void 0,focusable:!n},c,m,{as:r,ref:l,"data-disabled":n?"":void 0,onKeyDown:E(e.onKeyDown,(e=>{n||"Enter"!==e.key&&" "!==e.key||(" "===e.key&&e.preventDefault(),v())})),onMouseUp:E(e.onMouseUp,v),onMouseMove:E(e.onMouseMove,(e=>{if(n)d.onItemLeave();else{e.currentTarget.focus()}})),onMouseLeave:E(e.onMouseLeave,(()=>d.onItemLeave()))})))}));/*#__PURE__*/exports.MenuItem=_;const B=/*#__PURE__*/b.forwardRef(((e,t)=>{const{checked:r=!1,onCheckedChange:n,...o}=e;/*#__PURE__*/return b.createElement(z.Provider,{value:r},/*#__PURE__*/b.createElement(_,D({role:"menuitemcheckbox","aria-checked":r},o,{ref:t,"data-state":te(r),onSelect:E(o.onSelect,(()=>null==n?void 0:n(!r)),{checkForDefaultPrevented:!1})})))}));exports.MenuCheckboxItem=B;const $=/*#__PURE__*/b.createContext({}),j=/*#__PURE__*/b.forwardRef(((e,t)=>{const{value:n,onValueChange:o,...u}=e,a=r(o),c=b.useMemo((()=>({value:n,onValueChange:a})),[n,a]);/*#__PURE__*/return b.createElement($.Provider,{value:c},/*#__PURE__*/b.createElement(X,D({},u,{ref:t})))}));exports.MenuRadioGroup=j;const H=/*#__PURE__*/b.forwardRef(((e,t)=>{const{value:r,...n}=e,o=b.useContext($),u=r===o.value;/*#__PURE__*/return b.createElement(z.Provider,{value:u},/*#__PURE__*/b.createElement(_,D({role:"menuitemradio","aria-checked":u},n,{ref:t,"data-state":te(u),onSelect:E(n.onSelect,(()=>{var e;return null===(e=o.onValueChange)||void 0===e?void 0:e.call(o,r)}),{checkForDefaultPrevented:!1})})))}));exports.MenuRadioItem=H;const W="span",z=/*#__PURE__*/b.createContext(!1),J=/*#__PURE__*/b.forwardRef(((e,t)=>{const{as:r=W,forceMount:n,...o}=e,u=b.useContext(z);/*#__PURE__*/return b.createElement(p,{present:n||u},/*#__PURE__*/b.createElement(i,D({},o,{as:r,ref:t,"data-state":te(u)})))}));exports.MenuItemIndicator=J;const Q=d(s.Anchor,{displayName:"MenuAnchor"});exports.MenuAnchor=Q;const X=d(i,{defaultProps:{role:"group"},displayName:"MenuGroup"});exports.MenuGroup=X;const Y=d(i,{displayName:"MenuLabel"});exports.MenuLabel=Y;const Z=d(i,{defaultProps:{role:"separator","aria-orientation":"horizontal"},displayName:"MenuSeparator "});exports.MenuSeparator=Z;const ee=d(s.Arrow,{displayName:"MenuArrow"});function te(e){return e?"checked":"unchecked"}exports.MenuArrow=ee;const re=A;exports.Root=re;const ne=Q;exports.Anchor=ne;const oe=V;exports.Content=oe;const ue=X;exports.Group=ue;const ae=Y;exports.Label=ae;const ce=_;exports.Item=ce;const se=B;exports.CheckboxItem=se;const le=j;exports.RadioGroup=le;const ie=H;exports.RadioItem=ie;const de=J;exports.ItemIndicator=de;const pe=Z;exports.Separator=pe;const fe=ee;exports.Arrow=fe;
var e,t=require("@radix-ui/react-id").useId,n=require("@radix-ui/react-focus-guards").useFocusGuards,r=require("@radix-ui/react-use-callback-ref").useCallbackRef,o=require("@radix-ui/react-use-direction").useDirection,u=require("@radix-ui/react-slot").Slot,a=require("@radix-ui/react-roving-focus"),i=a.RovingFocusGroup,c=a.RovingFocusItem,s=require("@radix-ui/react-portal").Portal,l=I({},require("@radix-ui/react-popper")),d=require("@radix-ui/react-primitive"),f=d.Primitive,p=d.extendPrimitive,m=require("@radix-ui/react-presence").Presence,v=require("@radix-ui/react-focus-scope").FocusScope,g=require("@radix-ui/react-dismissable-layer").DismissableLayer,h=require("@radix-ui/react-context").createContext,x=require("@radix-ui/react-compose-refs"),b=x.useComposedRefs,C=x.composeRefs,E=require("@radix-ui/react-collection").createCollection,w=require("@radix-ui/primitive").composeEventHandlers,y=require("aria-hidden").hideOthers,R=require("react-remove-scroll").RemoveScroll,P=I({},require("react")),M=(e=require("@babel/runtime/helpers/extends"))&&e.__esModule?e.default:e;function I(e,t){return Object.keys(t).forEach((function(n){"default"!==n&&"__esModule"!==n&&Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[n]}})})),e}const k=["Enter"," "],D=["ArrowUp","PageDown","End"],S=["ArrowDown","PageUp","Home",...D],T={ltr:[...k,"ArrowRight"],rtl:[...k,"ArrowLeft"]},O={ltr:["ArrowLeft"],rtl:["ArrowRight"]},[L,F]=h("Menu"),A=e=>{const{open:t=!1,children:n,onOpenChange:u}=e,[a,i]=P.useState(null),c=P.useRef(!1),s=r(u),d=o(a,e.dir);return P.useEffect((()=>{const e=()=>c.current=!0,t=()=>c.current=!1;return document.addEventListener("keydown",e,{capture:!0}),document.addEventListener("pointerdown",t,{capture:!0}),document.addEventListener("pointermove",t,{capture:!0}),()=>{document.removeEventListener("keydown",e,{capture:!0}),document.removeEventListener("pointerdown",t,{capture:!0}),document.removeEventListener("pointermove",t,{capture:!0})}}),[]),/*#__PURE__*/P.createElement(l.Root,null,/*#__PURE__*/P.createElement(L,{isSubmenu:!1,isUsingKeyboardRef:c,dir:d,open:t,onOpenChange:s,content:a,onContentChange:i,onRootClose:P.useCallback((()=>s(!1)),[s])},n))};exports.Menu=A;const K=e=>{const{children:n,open:o=!1,onOpenChange:u}=e,a=F("MenuSub"),[i,c]=P.useState(null),[s,d]=P.useState(null),f=r(u);return P.useEffect((()=>(!1===a.open&&f(!1),()=>f(!1))),[a.open,f]),/*#__PURE__*/P.createElement(l.Root,null,/*#__PURE__*/P.createElement(L,{isSubmenu:!0,isUsingKeyboardRef:a.isUsingKeyboardRef,dir:a.dir,open:o,onOpenChange:f,content:s,onContentChange:d,onRootClose:a.onRootClose,contentId:t(),trigger:i,onTriggerChange:c,triggerId:t()},n))};exports.MenuSub=K;const[q,G,U]=E(),[V,N]=h("MenuContent"),X=/*#__PURE__*/P.forwardRef(((e,t)=>{const{forceMount:n,...r}=e,o=F("MenuContent");/*#__PURE__*/return P.createElement(m,{present:n||o.open},/*#__PURE__*/P.createElement(q,null,o.isSubmenu?/*#__PURE__*/P.createElement(B,M({},r,{ref:t})):/*#__PURE__*/P.createElement(_,M({},r,{ref:t}))))}));exports.MenuContent=X;const _=/*#__PURE__*/P.forwardRef(((e,t)=>{const n=F("MenuContent"),r=P.useRef(null),o=b(t,r);return P.useEffect((()=>{const e=r.current;if(e)return y(e)}),[]),/*#__PURE__*/P.createElement(j,M({},e,{ref:o,onDismiss:()=>n.onOpenChange(!1)}))})),B=/*#__PURE__*/P.forwardRef(((e,t)=>{const n=F("MenuContent"),r=P.useRef(null),o=b(t,r);return n.isSubmenu?/*#__PURE__*/P.createElement(j,M({id:n.contentId,"aria-labelledby":n.triggerId},e,{ref:o,align:"start",side:"rtl"===n.dir?"left":"right",portalled:!0,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:e=>{var t;n.isUsingKeyboardRef.current&&(null===(t=r.current)||void 0===t||t.focus()),e.preventDefault()},onCloseAutoFocus:e=>e.preventDefault(),onFocusOutside:w(e.onFocusOutside,(e=>{e.target!==n.trigger&&n.onOpenChange(!1)})),onEscapeKeyDown:w(e.onEscapeKeyDown,n.onRootClose),onKeyDown:w(e.onKeyDown,(e=>{const t=e.currentTarget.contains(e.target),r=O[n.dir].includes(e.key);var o;t&&r&&(n.onOpenChange(!1),null===(o=n.trigger)||void 0===o||o.focus())}))})):null})),j=/*#__PURE__*/P.forwardRef(((e,t)=>{const{loop:r=!1,trapFocus:o,onOpenAutoFocus:a,onCloseAutoFocus:c,disableOutsidePointerEvents:d,onEscapeKeyDown:f,onPointerDownOutside:p,onFocusOutside:m,onInteractOutside:h,onDismiss:x,disableOutsideScroll:C,portalled:E,...y}=e,I=F("MenuContent"),{getItems:k}=U(),[T,O]=P.useState(null),L=P.useRef(null),A=b(t,L,I.onContentChange),K=P.useRef(!1),q=P.useRef(0),G=P.useRef(""),N=P.useRef(0),X=P.useRef(null),_=P.useRef("right"),B=E?s:P.Fragment,j=C?R:P.Fragment,H=e=>{var t,n;const r=G.current+e,o=k().filter((e=>!e.disabled)),u=document.activeElement,a=null===(t=o.find((e=>e.ref.current===u)))||void 0===t?void 0:t.textValue,i=function(e,t,n){const r=t.length>1&&Array.from(t).every((e=>e===t[0]))?t[0]:t,o=n?e.indexOf(n):-1;let u=(a=e,i=Math.max(o,0),a.map(((e,t)=>a[(i+t)%a.length])));var a,i;1===r.length&&(u=u.filter((e=>e!==n)));const c=u.find((e=>e.toLowerCase().startsWith(r.toLowerCase())));return c!==n?c:void 0}(o.map((e=>e.textValue)),r,a),c=null===(n=o.find((e=>e.textValue===i)))||void 0===n?void 0:n.ref.current;!function e(t){G.current=t,window.clearTimeout(q.current),""!==t&&(q.current=window.setTimeout((()=>e("")),1e3))}(r),c&&setTimeout((()=>c.focus()))};P.useEffect((()=>()=>window.clearTimeout(q.current)),[]),n();const Y=P.useCallback((e=>{var t,n;return _.current===(null===(t=X.current)||void 0===t?void 0:t.side)&&function(e,t){if(!t)return!1;return function(e,t){const{x:n,y:r}=e;let o=!1;for(let e=0,u=t.length-1;e<t.length;u=e++){const a=t[e].x,i=t[e].y,c=t[u].x,s=t[u].y;i>r!=s>r&&n<(c-a)*(r-i)/(s-i)+a&&(o=!o)}return o}({x:e.clientX,y:e.clientY},t)}(e,null===(n=X.current)||void 0===n?void 0:n.area)}),[]);/*#__PURE__*/return P.createElement(B,null,/*#__PURE__*/P.createElement(j,null,/*#__PURE__*/P.createElement(V,{searchRef:G,onItemEnter:P.useCallback((e=>{Y(e)&&e.preventDefault()}),[Y]),onItemLeave:P.useCallback((e=>{var t;Y(e)||(null===(t=L.current)||void 0===t||t.focus(),O(null))}),[Y]),onTriggerLeave:P.useCallback((e=>{Y(e)&&e.preventDefault()}),[Y]),pointerGraceTimerRef:N,onPointerGraceIntentChange:P.useCallback((e=>{X.current=e}),[])},/*#__PURE__*/P.createElement(v,{as:u,trapped:o&&I.open,onMountAutoFocus:w(a,(e=>{var t;e.preventDefault(),null===(t=L.current)||void 0===t||t.focus()})),onUnmountAutoFocus:e=>{!d&&K.current?e.preventDefault():null==c||c(e)}},/*#__PURE__*/P.createElement(g,{as:u,disableOutsidePointerEvents:d,onEscapeKeyDown:w(f,(()=>{K.current=!1})),onPointerDownOutside:w(p,(e=>{const t=e.detail.originalEvent,n=0===t.button&&!1===t.ctrlKey;K.current=n}),{checkForDefaultPrevented:!1}),onFocusOutside:w(m,(e=>{o&&e.preventDefault()}),{checkForDefaultPrevented:!1}),onInteractOutside:h,onDismiss:x},/*#__PURE__*/P.createElement(i,{as:u,dir:I.dir,orientation:"vertical",loop:r,currentTabStopId:T,onCurrentTabStopIdChange:O,onEntryFocus:e=>{I.isUsingKeyboardRef.current||e.preventDefault()}},/*#__PURE__*/P.createElement(l.Content,M({role:"menu",dir:I.dir,"data-state":ce(I.open)},y,{ref:A,style:{outline:"none",...y.style},onKeyDown:w(y.onKeyDown,(e=>{const t=e.target,n=e.currentTarget.contains(t),r=e.ctrlKey||e.altKey||e.metaKey;n&&!r&&1===e.key.length&&H(e.key),"Tab"===e.key&&e.preventDefault();const o=L.current;if(e.target!==o)return;if(!S.includes(e.key))return;e.preventDefault();const u=k().filter((e=>!e.disabled)).map((e=>e.ref.current));D.includes(e.key)&&u.reverse(),function(e){const t=document.activeElement;for(const n of e){if(n===t)return;if(n.focus(),document.activeElement!==t)return}}(u)})),onBlur:w(e.onBlur,(e=>{e.currentTarget.contains(e.target)||(window.clearTimeout(q.current),G.current="")})),onPointerMove:w(e.onPointerMove,le((e=>{const t=e.target;e.currentTarget.contains(t)&&0!==e.movementX&&(_.current=e.movementX>0?"right":"left")})))}))))))))})),H="div",Y=/*#__PURE__*/P.forwardRef(((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,u=P.useRef(null),a=F("MenuItem"),i=N("MenuItem"),c=b(t,u),s=()=>{const e=u.current;if(!n&&e){const t=new Event("menu.itemSelect",{bubbles:!0,cancelable:!0});if(e.addEventListener("menu.itemSelect",(e=>null==r?void 0:r(e)),{once:!0}),e.dispatchEvent(t),t.defaultPrevented)return;a.onRootClose()}};/*#__PURE__*/return P.createElement(W,M({},o,{ref:c,disabled:n,onPointerUp:w(e.onPointerUp,s),onKeyDown:w(e.onKeyDown,(e=>{const t=""!==i.searchRef.current;n||t&&" "===e.key||k.includes(e.key)&&(" "===e.key&&e.preventDefault(),s())}))}))}));exports.MenuItem=Y;const z=/*#__PURE__*/P.forwardRef(((e,t)=>{const n=F("MenuSubTrigger"),r=N("MenuSubTrigger"),o=P.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:i}=r,c=P.useCallback((()=>{o.current&&window.clearTimeout(o.current),o.current=null}),[]);return P.useEffect((()=>c),[c]),P.useEffect((()=>{const e=a.current;return()=>{window.clearTimeout(e),i(null)}}),[a,i]),n.isSubmenu?/*#__PURE__*/P.createElement(re,{as:u},/*#__PURE__*/P.createElement(W,M({id:n.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":n.contentId,"data-state":ce(n.open)},e,{ref:C(t,n.onTriggerChange),onPointerUp:w(e.onPointerUp,(s=t=>{r.onItemEnter(t),t.defaultPrevented||e.disabled||n.open||n.onOpenChange(!0)},e=>"mouse"!==e.pointerType?s(e):void 0)),onPointerMove:w(e.onPointerMove,le((t=>{r.onItemEnter(t),t.defaultPrevented||e.disabled||n.open||o.current||(r.onPointerGraceIntentChange(null),o.current=window.setTimeout((()=>{n.onOpenChange(!0),c()}),100))}))),onPointerLeave:w(e.onPointerLeave,le((e=>{var t;c();const o=null===(t=n.content)||void 0===t?void 0:t.getBoundingClientRect();if(o){var u;const t=null===(u=n.content)||void 0===u?void 0:u.dataset.side,i="right"===t,c=i?-5:5,s=o[i?"left":"right"],l=o[i?"right":"left"];r.onPointerGraceIntentChange({area:[{x:e.clientX+c,y:e.clientY},{x:s,y:o.top},{x:l,y:o.top},{x:l,y:o.bottom},{x:s,y:o.bottom}],side:t}),window.clearTimeout(a.current),a.current=window.setTimeout((()=>r.onPointerGraceIntentChange(null)),300)}else{if(r.onTriggerLeave(e),e.defaultPrevented)return;r.onPointerGraceIntentChange(null)}}))),onKeyDown:w(e.onKeyDown,(t=>{const o=""!==r.searchRef.current;var u;e.disabled||o&&" "===t.key||T[n.dir].includes(t.key)&&(n.onOpenChange(!0),null===(u=n.content)||void 0===u||u.focus())}))}))):null;var s}));exports.MenuSubTrigger=z;const W=/*#__PURE__*/P.forwardRef(((e,t)=>{const{as:n=H,disabled:r=!1,textValue:o,...u}=e,a=P.useRef(null),i=b(t,a),s=N("MenuItem"),[l,d]=P.useState("");return P.useEffect((()=>{const e=a.current;var t;e&&d((null!==(t=e.textContent)&&void 0!==t?t:"").trim())}),[u.children]),/*#__PURE__*/P.createElement(G,{disabled:r,textValue:null!=o?o:l},/*#__PURE__*/P.createElement(c,M({role:"menuitem","aria-disabled":r||void 0,"data-disabled":r?"":void 0,focusable:!r},u,{as:n,ref:i,onPointerMove:w(e.onPointerMove,le((e=>{if(r)s.onItemLeave(e);else if(s.onItemEnter(e),!e.defaultPrevented){e.currentTarget.focus()}}))),onPointerLeave:w(e.onPointerLeave,le((e=>s.onItemLeave(e))))})))})),J=/*#__PURE__*/P.forwardRef(((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;/*#__PURE__*/return P.createElement(te.Provider,{value:n},/*#__PURE__*/P.createElement(Y,M({role:"menuitemcheckbox","aria-checked":n},o,{ref:t,"data-state":se(n),onSelect:w(o.onSelect,(()=>null==r?void 0:r(!n)),{checkForDefaultPrevented:!1})})))}));exports.MenuCheckboxItem=J;const Q=/*#__PURE__*/P.createContext({}),Z=/*#__PURE__*/P.forwardRef(((e,t)=>{const{value:n,onValueChange:o,...u}=e,a=r(o),i=P.useMemo((()=>({value:n,onValueChange:a})),[n,a]);/*#__PURE__*/return P.createElement(Q.Provider,{value:i},/*#__PURE__*/P.createElement(oe,M({},u,{ref:t})))}));exports.MenuRadioGroup=Z;const $=/*#__PURE__*/P.forwardRef(((e,t)=>{const{value:n,...r}=e,o=P.useContext(Q),u=n===o.value;/*#__PURE__*/return P.createElement(te.Provider,{value:u},/*#__PURE__*/P.createElement(Y,M({role:"menuitemradio","aria-checked":u},r,{ref:t,"data-state":se(u),onSelect:w(r.onSelect,(()=>{var e;return null===(e=o.onValueChange)||void 0===e?void 0:e.call(o,n)}),{checkForDefaultPrevented:!1})})))}));exports.MenuRadioItem=$;const ee="span",te=/*#__PURE__*/P.createContext(!1),ne=/*#__PURE__*/P.forwardRef(((e,t)=>{const{as:n=ee,forceMount:r,...o}=e,u=P.useContext(te);/*#__PURE__*/return P.createElement(m,{present:r||u},/*#__PURE__*/P.createElement(f,M({},o,{as:n,ref:t,"data-state":se(u)})))}));exports.MenuItemIndicator=ne;const re=p(l.Anchor,{displayName:"MenuAnchor"});exports.MenuAnchor=re;const oe=p(f,{defaultProps:{role:"group"},displayName:"MenuGroup"});exports.MenuGroup=oe;const ue=p(f,{displayName:"MenuLabel"});exports.MenuLabel=ue;const ae=p(f,{defaultProps:{role:"separator","aria-orientation":"horizontal"},displayName:"MenuSeparator "});exports.MenuSeparator=ae;const ie=p(l.Arrow,{displayName:"MenuArrow"});function ce(e){return e?"open":"closed"}function se(e){return e?"checked":"unchecked"}function le(e){return t=>"mouse"===t.pointerType?e(t):void 0}exports.MenuArrow=ie;const de=A;exports.Root=de;const fe=K;exports.Sub=fe;const pe=re;exports.Anchor=pe;const me=z;exports.SubTrigger=me;const ve=X;exports.Content=ve;const ge=oe;exports.Group=ge;const he=ue;exports.Label=he;const xe=Y;exports.Item=xe;const be=J;exports.CheckboxItem=be;const Ce=Z;exports.RadioGroup=Ce;const Ee=$;exports.RadioItem=Ee;const we=ne;exports.ItemIndicator=we;const ye=ae;exports.Separator=ye;const Re=ie;exports.Arrow=Re;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import{useFocusGuards as e}from"@radix-ui/react-focus-guards";import{useCallbackRef as t}from"@radix-ui/react-use-callback-ref";import{Slot as o}from"@radix-ui/react-slot";import{RovingFocusGroup as r,RovingFocusItem as n}from"@radix-ui/react-roving-focus";import{Portal as a}from"@radix-ui/react-portal";import*as u from"@radix-ui/react-popper";import{Primitive as c,extendPrimitive as l}from"@radix-ui/react-primitive";import{Presence as s}from"@radix-ui/react-presence";import{FocusScope as i}from"@radix-ui/react-focus-scope";import{DismissableLayer as d}from"@radix-ui/react-dismissable-layer";import{createContext as m}from"@radix-ui/react-context";import{composeRefs as p,useComposedRefs as f}from"@radix-ui/react-compose-refs";import{createCollection as v}from"@radix-ui/react-collection";import{composeEventHandlers as x}from"@radix-ui/primitive";import{hideOthers as M}from"aria-hidden";import{RemoveScroll as h}from"react-remove-scroll";import*as C from"react";import w from"@babel/runtime/helpers/esm/extends";function y(){const e=C.useRef(0),t=C.useRef(""),o=C.useCallback((r=>{t.current=r,window.clearTimeout(e.current),e.current=window.setTimeout((()=>o("")),1e3)}),[]);return{onKeyDownCapture:e=>{if(1===e.key.length&&!(e.ctrlKey||e.altKey||e.metaKey)){const r=e.currentTarget;o(t.current+e.key)," "!==e.key||t.current.startsWith(" ")||e.stopPropagation();const n=document.activeElement,a=n?E(n):void 0,u=function(e,t,o){const r=t.length>1&&Array.from(t).every((e=>e===t[0]))?t[0]:t,n=o?e.indexOf(o):-1;let a=(u=e,c=Math.max(n,0),u.map(((e,t)=>u[(c+t)%u.length])));var u,c;1===r.length&&(a=a.filter((e=>e!==o)));const l=a.find((e=>e.toLowerCase().startsWith(r.toLowerCase())));return l!==o?l:void 0}(Array.from(r.querySelectorAll(`[${b}]`)).map(E),t.current,a),c=r.querySelector(`[${b}="${u}"]`);c&&setTimeout((()=>c.focus()))}}}}const E=e=>{var t;return null!==(t=e.getAttribute(b))&&void 0!==t?t:""},b="data-radix-menu-typeahead-item";const D=["ArrowUp","PageDown","End"],k=["ArrowDown","PageUp","Home",...D],[I,g]=m("Menu");export const Menu=e=>{const{open:o=!1,children:r,onOpenChange:n}=e,a=t(n);/*#__PURE__*/return C.createElement(u.Root,null,/*#__PURE__*/C.createElement(I,{open:o,onOpenChange:a},r))};/*#__PURE__*/const[S,P,F]=v(),[A,R]=m("MenuContent");export const MenuContent=/*#__PURE__*/C.forwardRef(((e,t)=>{const{forceMount:o,...r}=e,n=g("MenuContent");/*#__PURE__*/return C.createElement(s,{present:o||n.open},/*#__PURE__*/C.createElement(S,null,/*#__PURE__*/C.createElement(K,w({"data-state":(a=n.open,a?"open":"closed")},r,{ref:t}))));var a}));const K=/*#__PURE__*/C.forwardRef(((t,n)=>{const{dir:c="ltr",loop:l=!1,trapFocus:s,onOpenAutoFocus:m,onCloseAutoFocus:f,disableOutsidePointerEvents:v,onEscapeKeyDown:E,onPointerDownOutside:b,onFocusOutside:I,onInteractOutside:S,disableOutsideScroll:P,portalled:R,...K}=t,O=g("MenuContent"),L=C.useRef(null),T=y(),{getItems:G}=F(),[V,N]=C.useState(null),[U,B]=C.useState(!1),$=R?a:C.Fragment,q=P?h:C.Fragment;return e(),C.useEffect((()=>{const e=L.current;if(e)return M(e)}),[]),/*#__PURE__*/C.createElement($,null,/*#__PURE__*/C.createElement(q,null,/*#__PURE__*/C.createElement(A,{onItemLeave:C.useCallback((()=>{var e;null===(e=L.current)||void 0===e||e.focus(),N(null)}),[])},/*#__PURE__*/C.createElement(i,{trapped:!U&&(s&&O.open),onMountAutoFocus:m,onUnmountAutoFocus:e=>{U?e.preventDefault():null==f||f(e)}},(e=>/*#__PURE__*/C.createElement(d,{disableOutsidePointerEvents:v,onEscapeKeyDown:E,onPointerDownOutside:x(b,(e=>{const t=0===e.button&&!1===e.ctrlKey;B(!v&&t),e.defaultPrevented&&B(!1)}),{checkForDefaultPrevented:!1}),onFocusOutside:x(I,(e=>{s&&e.preventDefault()}),{checkForDefaultPrevented:!1}),onInteractOutside:S,onDismiss:()=>O.onOpenChange(!1)},(t=>/*#__PURE__*/C.createElement(r,{as:o,dir:c,orientation:"vertical",loop:l,currentTabStopId:V,onCurrentTabStopIdChange:N,onEntryFocus:e=>e.preventDefault()},/*#__PURE__*/C.createElement(u.Content,w({role:"menu"},e,K,{ref:p(n,L,e.ref),style:{...t.style,outline:"none",...K.style},onBlurCapture:x(K.onBlurCapture,t.onBlurCapture,{checkForDefaultPrevented:!1}),onFocusCapture:x(K.onFocusCapture,t.onFocusCapture,{checkForDefaultPrevented:!1}),onMouseDownCapture:x(K.onMouseDownCapture,t.onMouseDownCapture,{checkForDefaultPrevented:!1}),onTouchStartCapture:x(K.onTouchStartCapture,t.onTouchStartCapture,{checkForDefaultPrevented:!1}),onKeyDownCapture:x(K.onKeyDownCapture,T.onKeyDownCapture),onKeyDown:x(K.onKeyDown,x(e.onKeyDown,(e=>{const t=L.current;if(e.target!==t)return;if(!k.includes(e.key))return;e.preventDefault();const o=G().filter((e=>!e.disabled)).map((e=>e.ref.current));D.includes(e.key)&&o.reverse(),function(e){const t=document.activeElement;for(const o of e){if(o===t)return;if(o.focus(),document.activeElement!==t)return}}(o)})))}))))))))))})),O="div";/*#__PURE__*/export const MenuItem=/*#__PURE__*/C.forwardRef(((e,t)=>{const{as:o=O,disabled:r=!1,textValue:a,onSelect:u,...c}=e,l=C.useRef(null),s=f(t,l),i=g("MenuItem"),d=R("MenuItem"),[m,p]=C.useState("");C.useEffect((()=>{const e=l.current;var t;e&&p((null!==(t=e.textContent)&&void 0!==t?t:"").trim())}),[c.children]);const v=function({textValue:e,disabled:t}){return{[b]:t?void 0:e}}({textValue:null!=a?a:m,disabled:r}),M=()=>{const e=l.current;if(!r&&e){var t;const o=new Event("menu.itemSelect",{bubbles:!0,cancelable:!0});if(e.dispatchEvent(o),o.defaultPrevented)return;null===(t=i.onOpenChange)||void 0===t||t.call(i,!1)}};return C.useEffect((()=>{const e=l.current;if(e){const t=e=>null==u?void 0:u(e);return e.addEventListener("menu.itemSelect",t),()=>e.removeEventListener("menu.itemSelect",t)}}),[u]),/*#__PURE__*/C.createElement(P,{disabled:r},/*#__PURE__*/C.createElement(n,w({role:"menuitem","aria-disabled":r||void 0,focusable:!r},c,v,{as:o,ref:s,"data-disabled":r?"":void 0,onKeyDown:x(e.onKeyDown,(e=>{r||"Enter"!==e.key&&" "!==e.key||(" "===e.key&&e.preventDefault(),M())})),onMouseUp:x(e.onMouseUp,M),onMouseMove:x(e.onMouseMove,(e=>{if(r)d.onItemLeave();else{e.currentTarget.focus()}})),onMouseLeave:x(e.onMouseLeave,(()=>d.onItemLeave()))})))}));/*#__PURE__*/export const MenuCheckboxItem=/*#__PURE__*/C.forwardRef(((e,t)=>{const{checked:o=!1,onCheckedChange:r,...n}=e;/*#__PURE__*/return C.createElement(G.Provider,{value:o},/*#__PURE__*/C.createElement(MenuItem,w({role:"menuitemcheckbox","aria-checked":o},n,{ref:t,"data-state":V(o),onSelect:x(n.onSelect,(()=>null==r?void 0:r(!o)),{checkForDefaultPrevented:!1})})))}));/*#__PURE__*/const L=/*#__PURE__*/C.createContext({});export const MenuRadioGroup=/*#__PURE__*/C.forwardRef(((e,o)=>{const{value:r,onValueChange:n,...a}=e,u=t(n),c=C.useMemo((()=>({value:r,onValueChange:u})),[r,u]);/*#__PURE__*/return C.createElement(L.Provider,{value:c},/*#__PURE__*/C.createElement(MenuGroup,w({},a,{ref:o})))}));/*#__PURE__*/export const MenuRadioItem=/*#__PURE__*/C.forwardRef(((e,t)=>{const{value:o,...r}=e,n=C.useContext(L),a=o===n.value;/*#__PURE__*/return C.createElement(G.Provider,{value:a},/*#__PURE__*/C.createElement(MenuItem,w({role:"menuitemradio","aria-checked":a},r,{ref:t,"data-state":V(a),onSelect:x(r.onSelect,(()=>{var e;return null===(e=n.onValueChange)||void 0===e?void 0:e.call(n,o)}),{checkForDefaultPrevented:!1})})))}));/*#__PURE__*/const T="span",G=/*#__PURE__*/C.createContext(!1);export const MenuItemIndicator=/*#__PURE__*/C.forwardRef(((e,t)=>{const{as:o=T,forceMount:r,...n}=e,a=C.useContext(G);/*#__PURE__*/return C.createElement(s,{present:r||a},/*#__PURE__*/C.createElement(c,w({},n,{as:o,ref:t,"data-state":V(a)})))}));/*#__PURE__*/export const MenuAnchor=l(u.Anchor,{displayName:"MenuAnchor"});export const MenuGroup=l(c,{defaultProps:{role:"group"},displayName:"MenuGroup"});export const MenuLabel=l(c,{displayName:"MenuLabel"});export const MenuSeparator=l(c,{defaultProps:{role:"separator","aria-orientation":"horizontal"},displayName:"MenuSeparator "});export const MenuArrow=l(u.Arrow,{displayName:"MenuArrow"});function V(e){return e?"checked":"unchecked"}export const Root=Menu;export const Anchor=MenuAnchor;export const Content=MenuContent;export const Group=MenuGroup;export const Label=MenuLabel;export const Item=MenuItem;export const CheckboxItem=MenuCheckboxItem;export const RadioGroup=MenuRadioGroup;export const RadioItem=MenuRadioItem;export const ItemIndicator=MenuItemIndicator;export const Separator=MenuSeparator;export const Arrow=MenuArrow;
import{useId as e}from"@radix-ui/react-id";import{useFocusGuards as t}from"@radix-ui/react-focus-guards";import{useCallbackRef as n}from"@radix-ui/react-use-callback-ref";import{useDirection as r}from"@radix-ui/react-use-direction";import{Slot as o}from"@radix-ui/react-slot";import{RovingFocusGroup as u,RovingFocusItem as a}from"@radix-ui/react-roving-focus";import{Portal as c}from"@radix-ui/react-portal";import*as i from"@radix-ui/react-popper";import{Primitive as l,extendPrimitive as s}from"@radix-ui/react-primitive";import{Presence as d}from"@radix-ui/react-presence";import{FocusScope as m}from"@radix-ui/react-focus-scope";import{DismissableLayer as f}from"@radix-ui/react-dismissable-layer";import{createContext as p}from"@radix-ui/react-context";import{useComposedRefs as v,composeRefs as g}from"@radix-ui/react-compose-refs";import{createCollection as h}from"@radix-ui/react-collection";import{composeEventHandlers as x}from"@radix-ui/primitive";import{hideOthers as b}from"aria-hidden";import{RemoveScroll as C}from"react-remove-scroll";import*as E from"react";import w from"@babel/runtime/helpers/esm/extends";const M=["Enter"," "],y=["ArrowUp","PageDown","End"],R=["ArrowDown","PageUp","Home",...y],I={ltr:[...M,"ArrowRight"],rtl:[...M,"ArrowLeft"]},P={ltr:["ArrowLeft"],rtl:["ArrowRight"]},[k,D]=p("Menu");export const Menu=e=>{const{open:t=!1,children:o,onOpenChange:u}=e,[a,c]=E.useState(null),l=E.useRef(!1),s=n(u),d=r(a,e.dir);return E.useEffect((()=>{const e=()=>l.current=!0,t=()=>l.current=!1;return document.addEventListener("keydown",e,{capture:!0}),document.addEventListener("pointerdown",t,{capture:!0}),document.addEventListener("pointermove",t,{capture:!0}),()=>{document.removeEventListener("keydown",e,{capture:!0}),document.removeEventListener("pointerdown",t,{capture:!0}),document.removeEventListener("pointermove",t,{capture:!0})}}),[]),/*#__PURE__*/E.createElement(i.Root,null,/*#__PURE__*/E.createElement(k,{isSubmenu:!1,isUsingKeyboardRef:l,dir:d,open:t,onOpenChange:s,content:a,onContentChange:c,onRootClose:E.useCallback((()=>s(!1)),[s])},o))};/*#__PURE__*/export const MenuSub=t=>{const{children:r,open:o=!1,onOpenChange:u}=t,a=D("MenuSub"),[c,l]=E.useState(null),[s,d]=E.useState(null),m=n(u);return E.useEffect((()=>(!1===a.open&&m(!1),()=>m(!1))),[a.open,m]),/*#__PURE__*/E.createElement(i.Root,null,/*#__PURE__*/E.createElement(k,{isSubmenu:!0,isUsingKeyboardRef:a.isUsingKeyboardRef,dir:a.dir,open:o,onOpenChange:m,content:s,onContentChange:d,onRootClose:a.onRootClose,contentId:e(),trigger:c,onTriggerChange:l,triggerId:e()},r))};/*#__PURE__*/const[S,T,O]=h(),[A,L]=p("MenuContent");export const MenuContent=/*#__PURE__*/E.forwardRef(((e,t)=>{const{forceMount:n,...r}=e,o=D("MenuContent");/*#__PURE__*/return E.createElement(d,{present:n||o.open},/*#__PURE__*/E.createElement(S,null,o.isSubmenu?/*#__PURE__*/E.createElement(F,w({},r,{ref:t})):/*#__PURE__*/E.createElement(K,w({},r,{ref:t}))))}));const K=/*#__PURE__*/E.forwardRef(((e,t)=>{const n=D("MenuContent"),r=E.useRef(null),o=v(t,r);return E.useEffect((()=>{const e=r.current;if(e)return b(e)}),[]),/*#__PURE__*/E.createElement(G,w({},e,{ref:o,onDismiss:()=>n.onOpenChange(!1)}))})),F=/*#__PURE__*/E.forwardRef(((e,t)=>{const n=D("MenuContent"),r=E.useRef(null),o=v(t,r);return n.isSubmenu?/*#__PURE__*/E.createElement(G,w({id:n.contentId,"aria-labelledby":n.triggerId},e,{ref:o,align:"start",side:"rtl"===n.dir?"left":"right",portalled:!0,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:e=>{var t;n.isUsingKeyboardRef.current&&(null===(t=r.current)||void 0===t||t.focus()),e.preventDefault()},onCloseAutoFocus:e=>e.preventDefault(),onFocusOutside:x(e.onFocusOutside,(e=>{e.target!==n.trigger&&n.onOpenChange(!1)})),onEscapeKeyDown:x(e.onEscapeKeyDown,n.onRootClose),onKeyDown:x(e.onKeyDown,(e=>{const t=e.currentTarget.contains(e.target),r=P[n.dir].includes(e.key);var o;t&&r&&(n.onOpenChange(!1),null===(o=n.trigger)||void 0===o||o.focus())}))})):null})),G=/*#__PURE__*/E.forwardRef(((e,n)=>{const{loop:r=!1,trapFocus:a,onOpenAutoFocus:l,onCloseAutoFocus:s,disableOutsidePointerEvents:d,onEscapeKeyDown:p,onPointerDownOutside:g,onFocusOutside:h,onInteractOutside:b,onDismiss:M,disableOutsideScroll:I,portalled:P,...k}=e,S=D("MenuContent"),{getItems:T}=O(),[L,K]=E.useState(null),F=E.useRef(null),G=v(n,F,S.onContentChange),U=E.useRef(!1),V=E.useRef(0),N=E.useRef(""),X=E.useRef(0),B=E.useRef(null),z=E.useRef("right"),W=P?c:E.Fragment,j=I?C:E.Fragment,q=e=>{var t,n;const r=N.current+e,o=T().filter((e=>!e.disabled)),u=document.activeElement,a=null===(t=o.find((e=>e.ref.current===u)))||void 0===t?void 0:t.textValue,c=function(e,t,n){const r=t.length>1&&Array.from(t).every((e=>e===t[0]))?t[0]:t,o=n?e.indexOf(n):-1;let u=(a=e,c=Math.max(o,0),a.map(((e,t)=>a[(c+t)%a.length])));var a,c;1===r.length&&(u=u.filter((e=>e!==n)));const i=u.find((e=>e.toLowerCase().startsWith(r.toLowerCase())));return i!==n?i:void 0}(o.map((e=>e.textValue)),r,a),i=null===(n=o.find((e=>e.textValue===c)))||void 0===n?void 0:n.ref.current;!function e(t){N.current=t,window.clearTimeout(V.current),""!==t&&(V.current=window.setTimeout((()=>e("")),1e3))}(r),i&&setTimeout((()=>i.focus()))};E.useEffect((()=>()=>window.clearTimeout(V.current)),[]),t();const J=E.useCallback((e=>{var t,n;return z.current===(null===(t=B.current)||void 0===t?void 0:t.side)&&function(e,t){if(!t)return!1;return function(e,t){const{x:n,y:r}=e;let o=!1;for(let e=0,u=t.length-1;e<t.length;u=e++){const a=t[e].x,c=t[e].y,i=t[u].x,l=t[u].y;c>r!=l>r&&n<(i-a)*(r-c)/(l-c)+a&&(o=!o)}return o}({x:e.clientX,y:e.clientY},t)}(e,null===(n=B.current)||void 0===n?void 0:n.area)}),[]);/*#__PURE__*/return E.createElement(W,null,/*#__PURE__*/E.createElement(j,null,/*#__PURE__*/E.createElement(A,{searchRef:N,onItemEnter:E.useCallback((e=>{J(e)&&e.preventDefault()}),[J]),onItemLeave:E.useCallback((e=>{var t;J(e)||(null===(t=F.current)||void 0===t||t.focus(),K(null))}),[J]),onTriggerLeave:E.useCallback((e=>{J(e)&&e.preventDefault()}),[J]),pointerGraceTimerRef:X,onPointerGraceIntentChange:E.useCallback((e=>{B.current=e}),[])},/*#__PURE__*/E.createElement(m,{as:o,trapped:a&&S.open,onMountAutoFocus:x(l,(e=>{var t;e.preventDefault(),null===(t=F.current)||void 0===t||t.focus()})),onUnmountAutoFocus:e=>{!d&&U.current?e.preventDefault():null==s||s(e)}},/*#__PURE__*/E.createElement(f,{as:o,disableOutsidePointerEvents:d,onEscapeKeyDown:x(p,(()=>{U.current=!1})),onPointerDownOutside:x(g,(e=>{const t=e.detail.originalEvent,n=0===t.button&&!1===t.ctrlKey;U.current=n}),{checkForDefaultPrevented:!1}),onFocusOutside:x(h,(e=>{a&&e.preventDefault()}),{checkForDefaultPrevented:!1}),onInteractOutside:b,onDismiss:M},/*#__PURE__*/E.createElement(u,{as:o,dir:S.dir,orientation:"vertical",loop:r,currentTabStopId:L,onCurrentTabStopIdChange:K,onEntryFocus:e=>{S.isUsingKeyboardRef.current||e.preventDefault()}},/*#__PURE__*/E.createElement(i.Content,w({role:"menu",dir:S.dir,"data-state":Y(S.open)},k,{ref:G,style:{outline:"none",...k.style},onKeyDown:x(k.onKeyDown,(e=>{const t=e.target,n=e.currentTarget.contains(t),r=e.ctrlKey||e.altKey||e.metaKey;n&&!r&&1===e.key.length&&q(e.key),"Tab"===e.key&&e.preventDefault();const o=F.current;if(e.target!==o)return;if(!R.includes(e.key))return;e.preventDefault();const u=T().filter((e=>!e.disabled)).map((e=>e.ref.current));y.includes(e.key)&&u.reverse(),function(e){const t=document.activeElement;for(const n of e){if(n===t)return;if(n.focus(),document.activeElement!==t)return}}(u)})),onBlur:x(e.onBlur,(e=>{e.currentTarget.contains(e.target)||(window.clearTimeout(V.current),N.current="")})),onPointerMove:x(e.onPointerMove,H((e=>{const t=e.target;e.currentTarget.contains(t)&&0!==e.movementX&&(z.current=e.movementX>0?"right":"left")})))}))))))))})),U="div";export const MenuItem=/*#__PURE__*/E.forwardRef(((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,u=E.useRef(null),a=D("MenuItem"),c=L("MenuItem"),i=v(t,u),l=()=>{const e=u.current;if(!n&&e){const t=new Event("menu.itemSelect",{bubbles:!0,cancelable:!0});if(e.addEventListener("menu.itemSelect",(e=>null==r?void 0:r(e)),{once:!0}),e.dispatchEvent(t),t.defaultPrevented)return;a.onRootClose()}};/*#__PURE__*/return E.createElement(V,w({},o,{ref:i,disabled:n,onPointerUp:x(e.onPointerUp,l),onKeyDown:x(e.onKeyDown,(e=>{const t=""!==c.searchRef.current;n||t&&" "===e.key||M.includes(e.key)&&(" "===e.key&&e.preventDefault(),l())}))}))}));/*#__PURE__*/export const MenuSubTrigger=/*#__PURE__*/E.forwardRef(((e,t)=>{const n=D("MenuSubTrigger"),r=L("MenuSubTrigger"),u=E.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:c}=r,i=E.useCallback((()=>{u.current&&window.clearTimeout(u.current),u.current=null}),[]);return E.useEffect((()=>i),[i]),E.useEffect((()=>{const e=a.current;return()=>{window.clearTimeout(e),c(null)}}),[a,c]),n.isSubmenu?/*#__PURE__*/E.createElement(MenuAnchor,{as:o},/*#__PURE__*/E.createElement(V,w({id:n.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":n.contentId,"data-state":Y(n.open)},e,{ref:g(t,n.onTriggerChange),onPointerUp:x(e.onPointerUp,(l=t=>{r.onItemEnter(t),t.defaultPrevented||e.disabled||n.open||n.onOpenChange(!0)},e=>"mouse"!==e.pointerType?l(e):void 0)),onPointerMove:x(e.onPointerMove,H((t=>{r.onItemEnter(t),t.defaultPrevented||e.disabled||n.open||u.current||(r.onPointerGraceIntentChange(null),u.current=window.setTimeout((()=>{n.onOpenChange(!0),i()}),100))}))),onPointerLeave:x(e.onPointerLeave,H((e=>{var t;i();const o=null===(t=n.content)||void 0===t?void 0:t.getBoundingClientRect();if(o){var u;const t=null===(u=n.content)||void 0===u?void 0:u.dataset.side,c="right"===t,i=c?-5:5,l=o[c?"left":"right"],s=o[c?"right":"left"];r.onPointerGraceIntentChange({area:[{x:e.clientX+i,y:e.clientY},{x:l,y:o.top},{x:s,y:o.top},{x:s,y:o.bottom},{x:l,y:o.bottom}],side:t}),window.clearTimeout(a.current),a.current=window.setTimeout((()=>r.onPointerGraceIntentChange(null)),300)}else{if(r.onTriggerLeave(e),e.defaultPrevented)return;r.onPointerGraceIntentChange(null)}}))),onKeyDown:x(e.onKeyDown,(t=>{const o=""!==r.searchRef.current;var u;e.disabled||o&&" "===t.key||I[n.dir].includes(t.key)&&(n.onOpenChange(!0),null===(u=n.content)||void 0===u||u.focus())}))}))):null;var l}));/*#__PURE__*/const V=/*#__PURE__*/E.forwardRef(((e,t)=>{const{as:n=U,disabled:r=!1,textValue:o,...u}=e,c=E.useRef(null),i=v(t,c),l=L("MenuItem"),[s,d]=E.useState("");return E.useEffect((()=>{const e=c.current;var t;e&&d((null!==(t=e.textContent)&&void 0!==t?t:"").trim())}),[u.children]),/*#__PURE__*/E.createElement(T,{disabled:r,textValue:null!=o?o:s},/*#__PURE__*/E.createElement(a,w({role:"menuitem","aria-disabled":r||void 0,"data-disabled":r?"":void 0,focusable:!r},u,{as:n,ref:i,onPointerMove:x(e.onPointerMove,H((e=>{if(r)l.onItemLeave(e);else if(l.onItemEnter(e),!e.defaultPrevented){e.currentTarget.focus()}}))),onPointerLeave:x(e.onPointerLeave,H((e=>l.onItemLeave(e))))})))}));export const MenuCheckboxItem=/*#__PURE__*/E.forwardRef(((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;/*#__PURE__*/return E.createElement(B.Provider,{value:n},/*#__PURE__*/E.createElement(MenuItem,w({role:"menuitemcheckbox","aria-checked":n},o,{ref:t,"data-state":z(n),onSelect:x(o.onSelect,(()=>null==r?void 0:r(!n)),{checkForDefaultPrevented:!1})})))}));/*#__PURE__*/const N=/*#__PURE__*/E.createContext({});export const MenuRadioGroup=/*#__PURE__*/E.forwardRef(((e,t)=>{const{value:r,onValueChange:o,...u}=e,a=n(o),c=E.useMemo((()=>({value:r,onValueChange:a})),[r,a]);/*#__PURE__*/return E.createElement(N.Provider,{value:c},/*#__PURE__*/E.createElement(MenuGroup,w({},u,{ref:t})))}));/*#__PURE__*/export const MenuRadioItem=/*#__PURE__*/E.forwardRef(((e,t)=>{const{value:n,...r}=e,o=E.useContext(N),u=n===o.value;/*#__PURE__*/return E.createElement(B.Provider,{value:u},/*#__PURE__*/E.createElement(MenuItem,w({role:"menuitemradio","aria-checked":u},r,{ref:t,"data-state":z(u),onSelect:x(r.onSelect,(()=>{var e;return null===(e=o.onValueChange)||void 0===e?void 0:e.call(o,n)}),{checkForDefaultPrevented:!1})})))}));/*#__PURE__*/const X="span",B=/*#__PURE__*/E.createContext(!1);export const MenuItemIndicator=/*#__PURE__*/E.forwardRef(((e,t)=>{const{as:n=X,forceMount:r,...o}=e,u=E.useContext(B);/*#__PURE__*/return E.createElement(d,{present:r||u},/*#__PURE__*/E.createElement(l,w({},o,{as:n,ref:t,"data-state":z(u)})))}));/*#__PURE__*/export const MenuAnchor=s(i.Anchor,{displayName:"MenuAnchor"});export const MenuGroup=s(l,{defaultProps:{role:"group"},displayName:"MenuGroup"});export const MenuLabel=s(l,{displayName:"MenuLabel"});export const MenuSeparator=s(l,{defaultProps:{role:"separator","aria-orientation":"horizontal"},displayName:"MenuSeparator "});export const MenuArrow=s(i.Arrow,{displayName:"MenuArrow"});function Y(e){return e?"open":"closed"}function z(e){return e?"checked":"unchecked"}function H(e){return t=>"mouse"===t.pointerType?e(t):void 0}export const Root=Menu;export const Sub=MenuSub;export const Anchor=MenuAnchor;export const SubTrigger=MenuSubTrigger;export const Content=MenuContent;export const Group=MenuGroup;export const Label=MenuLabel;export const Item=MenuItem;export const CheckboxItem=MenuCheckboxItem;export const RadioGroup=MenuRadioGroup;export const RadioItem=MenuRadioItem;export const ItemIndicator=MenuItemIndicator;export const Separator=MenuSeparator;export const Arrow=MenuArrow;
//# sourceMappingURL=index.module.js.map
{
"name": "@radix-ui/react-menu",
"version": "0.0.18",
"version": "0.0.19",
"license": "MIT",

@@ -22,16 +22,18 @@ "source": "src/index.ts",

"@radix-ui/primitive": "0.0.5",
"@radix-ui/react-collection": "0.0.12",
"@radix-ui/react-collection": "0.0.13",
"@radix-ui/react-compose-refs": "0.0.5",
"@radix-ui/react-context": "0.0.5",
"@radix-ui/react-dismissable-layer": "0.0.13",
"@radix-ui/react-dismissable-layer": "0.0.14",
"@radix-ui/react-focus-guards": "0.0.7",
"@radix-ui/react-focus-scope": "0.0.13",
"@radix-ui/react-polymorphic": "0.0.11",
"@radix-ui/react-popper": "0.0.16",
"@radix-ui/react-portal": "0.0.13",
"@radix-ui/react-focus-scope": "0.0.14",
"@radix-ui/react-id": "0.0.6",
"@radix-ui/react-polymorphic": "0.0.12",
"@radix-ui/react-popper": "0.0.17",
"@radix-ui/react-portal": "0.0.14",
"@radix-ui/react-presence": "0.0.14",
"@radix-ui/react-primitive": "0.0.13",
"@radix-ui/react-roving-focus": "0.0.13",
"@radix-ui/react-slot": "0.0.10",
"@radix-ui/react-primitive": "0.0.14",
"@radix-ui/react-roving-focus": "0.0.14",
"@radix-ui/react-slot": "0.0.11",
"@radix-ui/react-use-callback-ref": "0.0.5",
"@radix-ui/react-use-direction": "0.0.1",
"aria-hidden": "^1.1.1",

@@ -38,0 +40,0 @@ "react-remove-scroll": "^2.4.0"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc