@radix-ui/react-menu
Advanced tools
Comparing version 0.0.19 to 0.0.20
@@ -1,2 +0,2 @@ | ||
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; | ||
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"),c=a.RovingFocusGroup,i=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,c]=P.useState(null),i=P.useRef(!1),s=r(u),d=o(a,e.dir);return P.useEffect((()=>{const e=()=>i.current=!0,t=()=>i.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:i,dir:d,open:t,onOpenChange:s,content:a,onContentChange:c,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"),[c,i]=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:c,onTriggerChange:i,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:i,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=P.useRef(0),j=E?s:P.Fragment,H=C?R:P.Fragment,Y=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,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){G.current=t,window.clearTimeout(q.current),""!==t&&(q.current=window.setTimeout((()=>e("")),1e3))}(r),i&&setTimeout((()=>i.focus()))};P.useEffect((()=>()=>window.clearTimeout(q.current)),[]),n();const z=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,c=t[e].y,i=t[u].x,s=t[u].y;c>r!=s>r&&n<(i-a)*(r-c)/(s-c)+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(j,null,/*#__PURE__*/P.createElement(H,null,/*#__PURE__*/P.createElement(V,{searchRef:G,onItemEnter:P.useCallback((e=>{z(e)&&e.preventDefault()}),[z]),onItemLeave:P.useCallback((e=>{var t;z(e)||(null===(t=L.current)||void 0===t||t.focus(),O(null))}),[z]),onTriggerLeave:P.useCallback((e=>{z(e)&&e.preventDefault()}),[z]),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==i||i(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(c,{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":ie(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&&Y(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,n=B.current!==e.clientX;if(e.currentTarget.contains(t)&&n){const t=e.clientX>B.current?"right":"left";_.current=t,B.current=e.clientX}})))}))))))))})),H="div",Y=/*#__PURE__*/P.forwardRef(((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,u=P.useRef(null),a=F("MenuItem"),c=N("MenuItem"),i=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:i,disabled:n,onPointerUp:w(e.onPointerUp,s),onKeyDown:w(e.onKeyDown,(e=>{const t=""!==c.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:c}=r,i=P.useCallback((()=>{o.current&&window.clearTimeout(o.current),o.current=null}),[]);return P.useEffect((()=>i),[i]),P.useEffect((()=>{const e=a.current;return()=>{window.clearTimeout(e),c(null)}}),[a,c]),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":ie(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),i()}),100))}))),onPointerLeave:w(e.onPointerLeave,le((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,s=o[c?"left":"right"],l=o[c?"right":"left"];r.onPointerGraceIntentChange({area:[{x:e.clientX+i,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),c=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(i,M({role:"menuitem","aria-disabled":r||void 0,"data-disabled":r?"":void 0,focusable:!r},u,{as:n,ref:c,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),c=P.useMemo((()=>({value:n,onValueChange:a})),[n,a]);/*#__PURE__*/return P.createElement(Q.Provider,{value:c},/*#__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 ce=p(l.Arrow,{displayName:"MenuArrow"});function ie(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=ce;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=ce;exports.Arrow=Re; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
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; | ||
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=E.useRef(0),j=P?c:E.Fragment,q=I?C:E.Fragment,J=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 Q=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(j,null,/*#__PURE__*/E.createElement(q,null,/*#__PURE__*/E.createElement(A,{searchRef:N,onItemEnter:E.useCallback((e=>{Q(e)&&e.preventDefault()}),[Q]),onItemLeave:E.useCallback((e=>{var t;Q(e)||(null===(t=F.current)||void 0===t||t.focus(),K(null))}),[Q]),onTriggerLeave:E.useCallback((e=>{Q(e)&&e.preventDefault()}),[Q]),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&&J(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,n=W.current!==e.clientX;if(e.currentTarget.contains(t)&&n){const t=e.clientX>W.current?"right":"left";z.current=t,W.current=e.clientX}})))}))))))))})),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.19", | ||
"version": "0.0.20", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "source": "src/index.ts", |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
167809
246
0