@radix-ui/react-navigation-menu 0.1.3-rc.4 → 0.1.3-rc.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +847 -1
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +828 -1
- package/dist/index.module.js.map +1 -1
- package/package.json +14 -14
package/dist/index.module.js
CHANGED
|
@@ -1,2 +1,829 @@
|
|
|
1
|
-
import*as e from"@radix-ui/react-visually-hidden";import{useCallbackRef as t}from"@radix-ui/react-use-callback-ref";import{useLayoutEffect as n}from"@radix-ui/react-use-layout-effect";import{usePrevious as o}from"@radix-ui/react-use-previous";import{DismissableLayer as r}from"@radix-ui/react-dismissable-layer";import{createCollection as a}from"@radix-ui/react-collection";import{useId as i}from"@radix-ui/react-id";import{Presence as u}from"@radix-ui/react-presence";import{useDirection as s}from"@radix-ui/react-direction";import{composeRefs as c,useComposedRefs as l}from"@radix-ui/react-compose-refs";import{useControllableState as d}from"@radix-ui/react-use-controllable-state";import{Primitive as v}from"@radix-ui/react-primitive";import{composeEventHandlers as f}from"@radix-ui/primitive";import{createContextScope as m}from"@radix-ui/react-context";import p from"react-dom";import*as g from"react";import M from"@babel/runtime/helpers/esm/extends";const[E,w,N]=a("NavigationMenu"),[x,R,h]=a("NavigationMenu"),[C,b]=m("NavigationMenu",[N,h]);export{b as createNavigationMenuScope};const[_,y]=C("NavigationMenu"),[I,P]=C("NavigationMenu");export const NavigationMenu=/*#__PURE__*/g.forwardRef(((e,t)=>{const{__scopeNavigationMenu:n,value:o,onValueChange:r,defaultValue:a,orientation:i="horizontal",dir:u,...c}=e,[d,f]=g.useState(null),m=l(t,(e=>f(e))),p=s(u);/*#__PURE__*/return g.createElement(T,{scope:n,isRootMenu:!0,value:o,onValueChange:r,defaultValue:a,dir:p,orientation:i,rootNavigationMenu:d},/*#__PURE__*/g.createElement(v.nav,M({"aria-label":"Main","data-orientation":i,dir:p},c,{ref:m})))}));/*#__PURE__*/export const NavigationMenuSub=/*#__PURE__*/g.forwardRef(((e,t)=>{const{__scopeNavigationMenu:n,value:o,onValueChange:r,defaultValue:a,orientation:i="horizontal",...u}=e,s=y("NavigationMenuSub",n);/*#__PURE__*/return g.createElement(T,{scope:n,isRootMenu:!1,value:o,onValueChange:r,defaultValue:a,dir:s.dir,orientation:i,rootNavigationMenu:s.rootNavigationMenu},/*#__PURE__*/g.createElement(v.div,M({"data-orientation":i},u,{ref:t})))}));/*#__PURE__*/const T=e=>{const{scope:t,isRootMenu:n,rootNavigationMenu:r,value:a,onValueChange:u,defaultValue:s,dir:c,orientation:l,children:v}=e,[f,m]=g.useState(null),[p,M]=g.useState(new Map),[w,N]=g.useState(null),x=g.useRef(0),[R="",h]=d({prop:a,onChange:u,defaultProp:s});return g.useEffect((()=>()=>window.clearTimeout(x.current)),[x]),/*#__PURE__*/g.createElement(_,{scope:t,isRootMenu:n,rootNavigationMenu:r,value:R,previousValue:o(R),baseId:i(),dir:c,orientation:l,viewport:f,onViewportChange:m,indicatorTrack:w,onIndicatorTrackChange:N,onItemOver:g.useCallback((e=>{n&&window.clearTimeout(x.current),h(e)}),[h,n]),onItemLeave:g.useCallback((()=>{n&&(window.clearTimeout(x.current),x.current=window.setTimeout((()=>h("")),150))}),[h,n]),onItemSelect:g.useCallback((e=>{h((t=>n&&t===e?"":e))}),[h,n]),onItemDismiss:g.useCallback((()=>h("")),[h]),onViewportContentChange:g.useCallback(((e,t)=>{M((n=>(n.set(e,t),new Map(n))))}),[]),onViewportContentRemove:g.useCallback((e=>{M((t=>t.has(e)?(t.delete(e),new Map(t)):t))}),[])},/*#__PURE__*/g.createElement(E.Provider,{scope:t},/*#__PURE__*/g.createElement(I,{scope:t,items:p},v)))};export const NavigationMenuList=/*#__PURE__*/g.forwardRef(((e,t)=>{const{__scopeNavigationMenu:n,...o}=e,r=y("NavigationMenuList",n),a=/*#__PURE__*/g.createElement(v.ul,M({"data-orientation":r.orientation},o,{ref:t}));/*#__PURE__*/return g.createElement(v.div,{style:{position:"relative"},ref:r.onIndicatorTrackChange},/*#__PURE__*/g.createElement(E.Slot,{scope:n},r.isRootMenu?/*#__PURE__*/g.createElement(S,{asChild:!0},a):a))}));/*#__PURE__*/const[L,k]=C("NavigationMenuItem");export const NavigationMenuItem=/*#__PURE__*/g.forwardRef(((e,t)=>{const{__scopeNavigationMenu:n,value:o,...r}=e,a=i(),u=o||a||"LEGACY_REACT_AUTO_VALUE",s=g.useRef(null),c=g.useRef(null),l=g.useRef(null),d=g.useRef((()=>{})),f=g.useCallback(((e="start")=>{if(s.current){d.current();const t=z(s.current);t.length&&$("start"===e?t:t.reverse())}}),[]),m=g.useCallback((()=>{if(s.current){const e=z(s.current);e.length&&(d.current=function(e){return e.forEach((e=>{e.dataset.tabindex=e.getAttribute("tabindex")||"",e.setAttribute("tabindex","-1")})),()=>{e.forEach((e=>{const t=e.dataset.tabindex;e.setAttribute("tabindex",t)}))}}(e))}}),[]);/*#__PURE__*/return g.createElement(L,{scope:n,value:u,triggerRef:c,contentRef:s,focusProxyRef:l,onEntryKeyDown:f,onFocusProxyEnter:f,onRootContentClose:m,onContentFocusOutside:m},/*#__PURE__*/g.createElement(v.li,M({},r,{ref:t})))}));/*#__PURE__*/export const NavigationMenuTrigger=/*#__PURE__*/g.forwardRef(((t,n)=>{const{__scopeNavigationMenu:o,disabled:r,...a}=t,i=y("NavigationMenuTrigger",t.__scopeNavigationMenu),u=k("NavigationMenuTrigger",t.__scopeNavigationMenu),s=g.useRef(null),c=l(s,u.triggerRef,n),d=H(i.baseId,u.value),m=W(i.baseId,u.value),p=g.useRef(!1),w=u.value===i.value;/*#__PURE__*/return g.createElement(g.Fragment,null,/*#__PURE__*/g.createElement(E.ItemSlot,{scope:o,value:u.value},/*#__PURE__*/g.createElement(K,{asChild:!0},/*#__PURE__*/g.createElement(v.button,M({id:d,disabled:r,"data-disabled":r?"":void 0,"data-state":B(w),"aria-expanded":w,"aria-controls":m},a,{ref:c,onPointerEnter:f(t.onPointerEnter,(()=>{p.current=!1})),onPointerMove:f(t.onPointerMove,G((()=>{r||p.current||i.onItemOver(u.value)}))),onPointerLeave:f(t.onPointerLeave,G((()=>{r||i.onItemLeave()}))),onClick:f(t.onClick,(()=>{i.onItemSelect(u.value),p.current=w})),onKeyDown:f(t.onKeyDown,(e=>{const t={horizontal:"ArrowDown",vertical:"rtl"===i.dir?"ArrowLeft":"ArrowRight"}[i.orientation];w&&e.key===t&&(u.onEntryKeyDown(),e.preventDefault())}))})))),w&&/*#__PURE__*/g.createElement(g.Fragment,null,/*#__PURE__*/g.createElement(e.Root,{"aria-hidden":!0,tabIndex:0,ref:u.focusProxyRef,onFocus:e=>{const t=u.contentRef.current,n=e.relatedTarget,o=n===s.current,r=null==t?void 0:t.contains(n);!o&&r||u.onFocusProxyEnter(o?"start":"end")}}),i.viewport&&/*#__PURE__*/g.createElement("span",{"aria-owns":m})))}));/*#__PURE__*/export const NavigationMenuLink=/*#__PURE__*/g.forwardRef(((e,t)=>{const{__scopeNavigationMenu:n,active:o,...r}=e;/*#__PURE__*/return g.createElement(K,{asChild:!0},/*#__PURE__*/g.createElement(v.a,M({"data-active":o?"":void 0,"aria-current":o?"page":void 0},r,{ref:t})))}));/*#__PURE__*/export const NavigationMenuIndicator=/*#__PURE__*/g.forwardRef(((e,t)=>{const{forceMount:n,...o}=e,r=y("NavigationMenuIndicator",e.__scopeNavigationMenu),a=Boolean(r.value);return r.indicatorTrack?/*#__PURE__*/p.createPortal(/*#__PURE__*/g.createElement(u,{present:n||a},/*#__PURE__*/g.createElement(V,M({},o,{ref:t}))),r.indicatorTrack):null}));/*#__PURE__*/const V=/*#__PURE__*/g.forwardRef(((e,t)=>{const{__scopeNavigationMenu:n,...o}=e,r=y("NavigationMenuIndicator",n),a=w(n),[i,u]=g.useState(null),[s,c]=g.useState(null),l="horizontal"===r.orientation,d=Boolean(r.value);g.useEffect((()=>{var e;const t=null===(e=a().find((e=>e.value===r.value)))||void 0===e?void 0:e.ref.current;t&&u(t)}),[a,r.value]);const f=()=>{i&&c({size:l?i.offsetWidth:i.offsetHeight,offset:l?i.offsetLeft:i.offsetTop})};return U(i,f),U(r.indicatorTrack,f),s?/*#__PURE__*/g.createElement(v.div,M({"aria-hidden":!0,"data-state":d?"visible":"hidden","data-orientation":r.orientation},o,{ref:t,style:{position:"absolute",...l?{left:0,width:s.size+"px",transform:`translateX(${s.offset}px)`}:{top:0,height:s.size+"px",transform:`translateY(${s.offset}px)`},...o.style}})):null}));export const NavigationMenuContent=/*#__PURE__*/g.forwardRef(((e,t)=>{const{forceMount:n,...o}=e,r=y("NavigationMenuContent",e.__scopeNavigationMenu),a=k("NavigationMenuContent",e.__scopeNavigationMenu),i=l(a.contentRef,t),s=a.value===r.value,c={value:a.value,triggerRef:a.triggerRef,focusProxyRef:a.focusProxyRef,onContentFocusOutside:a.onContentFocusOutside,onRootContentClose:a.onRootContentClose,...o};return r.viewport?/*#__PURE__*/g.createElement(D,M({forceMount:n},c,{ref:i})):/*#__PURE__*/g.createElement(u,{present:n||s},/*#__PURE__*/g.createElement(F,M({"data-state":B(s)},c,{ref:i,onPointerEnter:f(e.onPointerEnter,(()=>{r.onItemOver(a.value)})),onPointerLeave:f(e.onPointerLeave,G(r.onItemLeave)),style:{pointerEvents:!s&&r.isRootMenu?"none":void 0,...c.style}})))}));/*#__PURE__*/const D=/*#__PURE__*/g.forwardRef(((e,t)=>{const o=y("NavigationMenuContent",e.__scopeNavigationMenu),{onViewportContentChange:r,onViewportContentRemove:a}=o;return n((()=>{r(e.value,{ref:t,...e})}),[e,t,r]),n((()=>()=>a(e.value)),[e.value,a]),null})),F=/*#__PURE__*/g.forwardRef(((e,t)=>{const{__scopeNavigationMenu:n,value:o,triggerRef:a,focusProxyRef:i,onRootContentClose:u,onContentFocusOutside:s,...c}=e,d=y("NavigationMenuContent",n),v=g.useRef(null),m=l(v,t),p=H(d.baseId,o),E=W(d.baseId,o),N=w(n),x=g.useRef(null),{onItemDismiss:R}=d;g.useEffect((()=>{const e=v.current;if(d.isRootMenu&&e){const t=()=>{var t;R(),u(),e.contains(document.activeElement)&&(null===(t=a.current)||void 0===t||t.focus())};return e.addEventListener("navigationMenu.contentDismiss",t),()=>e.removeEventListener("navigationMenu.contentDismiss",t)}}),[d.isRootMenu,e.value,a,R,u]);const h=g.useMemo((()=>{const e=N().map((e=>e.value));"rtl"===d.dir&&e.reverse();const t=e.indexOf(d.value),n=e.indexOf(d.previousValue),r=o===d.value,a=n===e.indexOf(o);if(!r&&!a)return x.current;const i=(()=>{if(t!==n){if(r&&-1!==n)return t>n?"from-end":"from-start";if(a&&-1!==t)return t>n?"to-start":"to-end"}return null})();return x.current=i,i}),[d.previousValue,d.value,d.dir,N,o]);/*#__PURE__*/return g.createElement(S,{asChild:!0},/*#__PURE__*/g.createElement(r,M({id:E,"aria-labelledby":p,"data-motion":h,"data-orientation":d.orientation},c,{ref:m,onDismiss:()=>{var e;const t=new Event("navigationMenu.contentDismiss",{bubbles:!0,cancelable:!0});null===(e=v.current)||void 0===e||e.dispatchEvent(t)},onFocusOutside:f(e.onFocusOutside,(e=>{var t;s();const n=e.target;null!==(t=d.rootNavigationMenu)&&void 0!==t&&t.contains(n)&&e.preventDefault()})),onPointerDownOutside:f(e.onPointerDownOutside,(e=>{var t;const n=e.target,o=N().some((e=>{var t;return null===(t=e.ref.current)||void 0===t?void 0:t.contains(n)})),r=d.isRootMenu&&(null===(t=d.viewport)||void 0===t?void 0:t.contains(n));(o||r||!d.isRootMenu)&&e.preventDefault()})),onKeyDown:f(e.onKeyDown,(e=>{const t=e.altKey||e.ctrlKey||e.metaKey;if("Tab"===e.key&&!t){const t=z(e.currentTarget),o=document.activeElement,r=t.findIndex((e=>e===o));var n;if($(e.shiftKey?t.slice(0,r).reverse():t.slice(r+1,t.length)))e.preventDefault();else null===(n=i.current)||void 0===n||n.focus()}}))})))}));export const NavigationMenuViewport=/*#__PURE__*/g.forwardRef(((e,t)=>{const{forceMount:n,...o}=e,r=y("NavigationMenuViewport",e.__scopeNavigationMenu),a=Boolean(r.value);/*#__PURE__*/return g.createElement(u,{present:n||a},/*#__PURE__*/g.createElement(A,M({},o,{ref:t})))}));/*#__PURE__*/const A=/*#__PURE__*/g.forwardRef(((e,t)=>{const{__scopeNavigationMenu:n,children:o,...r}=e,a=y("NavigationMenuViewport",n),i=l(t,a.onViewportChange),s=P("NavigationMenuContent",e.__scopeNavigationMenu),[d,m]=g.useState(null),[p,E]=g.useState(null),w=d?(null==d?void 0:d.width)+"px":void 0,N=d?(null==d?void 0:d.height)+"px":void 0,x=Boolean(a.value),R=x?a.value:a.previousValue;return U(p,(()=>{p&&m({width:p.offsetWidth,height:p.offsetHeight})})),/*#__PURE__*/g.createElement(v.div,M({"data-state":B(x),"data-orientation":a.orientation},r,{ref:i,style:{pointerEvents:!x&&a.isRootMenu?"none":void 0,"--radix-navigation-menu-viewport-width":w,"--radix-navigation-menu-viewport-height":N,...r.style},onPointerEnter:f(e.onPointerEnter,(()=>{a.onItemOver(R)})),onPointerLeave:f(e.onPointerLeave,G(a.onItemLeave))}),Array.from(s.items).map((([e,{ref:t,forceMount:n,...o}])=>{const r=R===e;/*#__PURE__*/return g.createElement(u,{key:e,present:n||r},/*#__PURE__*/g.createElement(F,M({},o,{ref:c(t,(e=>{r&&e&&E(e)}))})))})))})),S=/*#__PURE__*/g.forwardRef(((e,t)=>{const{__scopeNavigationMenu:n,...o}=e,r=y("FocusGroup",n);/*#__PURE__*/return g.createElement(x.Provider,{scope:n},/*#__PURE__*/g.createElement(x.Slot,{scope:n},/*#__PURE__*/g.createElement(v.div,M({dir:r.dir},o,{ref:t}))))})),O=["ArrowRight","ArrowLeft","ArrowUp","ArrowDown"],K=/*#__PURE__*/g.forwardRef(((e,t)=>{const{__scopeNavigationMenu:n,...o}=e,r=R(n),a=y("FocusGroupItem",n);/*#__PURE__*/return g.createElement(x.ItemSlot,{scope:n},/*#__PURE__*/g.createElement(v.button,M({},o,{ref:t,onKeyDown:f(e.onKeyDown,(e=>{if(["Home","End",...O].includes(e.key)){let t=r().map((e=>e.ref.current));if(["rtl"===a.dir?"ArrowRight":"ArrowLeft","ArrowUp","End"].includes(e.key)&&t.reverse(),O.includes(e.key)){const n=t.indexOf(e.currentTarget);t=t.slice(n+1)}setTimeout((()=>$(t))),e.preventDefault()}}))})))}));function z(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>{const t="INPUT"===e.tagName&&"hidden"===e.type;return e.disabled||e.hidden||t?NodeFilter.FILTER_SKIP:e.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function $(e){const t=document.activeElement;return e.some((e=>e===t||(e.focus(),document.activeElement!==t)))}function U(e,o){const r=t(o);n((()=>{let t=0;if(e){const n=new ResizeObserver((()=>{cancelAnimationFrame(t),t=window.requestAnimationFrame(r)}));return n.observe(e),()=>{window.cancelAnimationFrame(t),n.unobserve(e)}}}),[e,r])}function B(e){return e?"open":"closed"}function H(e,t){return`${e}-trigger-${t}`}function W(e,t){return`${e}-content-${t}`}function G(e){return t=>"mouse"===t.pointerType?e(t):void 0}export const Root=NavigationMenu;export const Sub=NavigationMenuSub;export const List=NavigationMenuList;export const Item=NavigationMenuItem;export const Trigger=NavigationMenuTrigger;export const Link=NavigationMenuLink;export const Indicator=NavigationMenuIndicator;export const Content=NavigationMenuContent;export const Viewport=NavigationMenuViewport;
|
|
1
|
+
import $yHMN2$babelruntimehelpersesmextends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import {forwardRef as $yHMN2$forwardRef, useState as $yHMN2$useState, createElement as $yHMN2$createElement, useRef as $yHMN2$useRef, useEffect as $yHMN2$useEffect, useCallback as $yHMN2$useCallback, Fragment as $yHMN2$Fragment, useMemo as $yHMN2$useMemo} from "react";
|
|
3
|
+
import $yHMN2$reactdom from "react-dom";
|
|
4
|
+
import {createContextScope as $yHMN2$createContextScope} from "@radix-ui/react-context";
|
|
5
|
+
import {composeEventHandlers as $yHMN2$composeEventHandlers} from "@radix-ui/primitive";
|
|
6
|
+
import {Primitive as $yHMN2$Primitive} from "@radix-ui/react-primitive";
|
|
7
|
+
import {useControllableState as $yHMN2$useControllableState} from "@radix-ui/react-use-controllable-state";
|
|
8
|
+
import {useComposedRefs as $yHMN2$useComposedRefs, composeRefs as $yHMN2$composeRefs} from "@radix-ui/react-compose-refs";
|
|
9
|
+
import {useDirection as $yHMN2$useDirection} from "@radix-ui/react-direction";
|
|
10
|
+
import {Presence as $yHMN2$Presence} from "@radix-ui/react-presence";
|
|
11
|
+
import {useId as $yHMN2$useId} from "@radix-ui/react-id";
|
|
12
|
+
import {createCollection as $yHMN2$createCollection} from "@radix-ui/react-collection";
|
|
13
|
+
import {DismissableLayer as $yHMN2$DismissableLayer} from "@radix-ui/react-dismissable-layer";
|
|
14
|
+
import {usePrevious as $yHMN2$usePrevious} from "@radix-ui/react-use-previous";
|
|
15
|
+
import {useLayoutEffect as $yHMN2$useLayoutEffect} from "@radix-ui/react-use-layout-effect";
|
|
16
|
+
import {useCallbackRef as $yHMN2$useCallbackRef} from "@radix-ui/react-use-callback-ref";
|
|
17
|
+
import {Root as $yHMN2$Root} from "@radix-ui/react-visually-hidden";
|
|
18
|
+
|
|
19
|
+
function $parcel$export(e, n, v, s) {
|
|
20
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
21
|
+
}
|
|
22
|
+
var $322c88a641701f3b$exports = {};
|
|
23
|
+
|
|
24
|
+
$parcel$export($322c88a641701f3b$exports, "createNavigationMenuScope", () => $322c88a641701f3b$export$fb8ea5af8c9fcdf0);
|
|
25
|
+
$parcel$export($322c88a641701f3b$exports, "NavigationMenu", () => $322c88a641701f3b$export$5b2278cf1e8bcae2);
|
|
26
|
+
$parcel$export($322c88a641701f3b$exports, "NavigationMenuSub", () => $322c88a641701f3b$export$5958edd6c4ee7c79);
|
|
27
|
+
$parcel$export($322c88a641701f3b$exports, "NavigationMenuList", () => $322c88a641701f3b$export$c361068a95fd2286);
|
|
28
|
+
$parcel$export($322c88a641701f3b$exports, "NavigationMenuItem", () => $322c88a641701f3b$export$ffdbb83a2de845c2);
|
|
29
|
+
$parcel$export($322c88a641701f3b$exports, "NavigationMenuTrigger", () => $322c88a641701f3b$export$37fe8002734d8f2);
|
|
30
|
+
$parcel$export($322c88a641701f3b$exports, "NavigationMenuLink", () => $322c88a641701f3b$export$6893bf21536567da);
|
|
31
|
+
$parcel$export($322c88a641701f3b$exports, "NavigationMenuIndicator", () => $322c88a641701f3b$export$8ddb526647c0d8fb);
|
|
32
|
+
$parcel$export($322c88a641701f3b$exports, "NavigationMenuContent", () => $322c88a641701f3b$export$38e00e996c2f93f7);
|
|
33
|
+
$parcel$export($322c88a641701f3b$exports, "NavigationMenuViewport", () => $322c88a641701f3b$export$ee880b97cc6d44a5);
|
|
34
|
+
$parcel$export($322c88a641701f3b$exports, "Root", () => $322c88a641701f3b$export$be92b6f5f03c0fe9);
|
|
35
|
+
$parcel$export($322c88a641701f3b$exports, "Sub", () => $322c88a641701f3b$export$d7a01e11500dfb6f);
|
|
36
|
+
$parcel$export($322c88a641701f3b$exports, "List", () => $322c88a641701f3b$export$54c2e3dc7acea9f5);
|
|
37
|
+
$parcel$export($322c88a641701f3b$exports, "Item", () => $322c88a641701f3b$export$6d08773d2e66f8f2);
|
|
38
|
+
$parcel$export($322c88a641701f3b$exports, "Trigger", () => $322c88a641701f3b$export$41fb9f06171c75f4);
|
|
39
|
+
$parcel$export($322c88a641701f3b$exports, "Link", () => $322c88a641701f3b$export$a6c7ac8248d6e38a);
|
|
40
|
+
$parcel$export($322c88a641701f3b$exports, "Indicator", () => $322c88a641701f3b$export$adb584737d712b70);
|
|
41
|
+
$parcel$export($322c88a641701f3b$exports, "Content", () => $322c88a641701f3b$export$7c6e2c02157bb7d2);
|
|
42
|
+
$parcel$export($322c88a641701f3b$exports, "Viewport", () => $322c88a641701f3b$export$d5c6c08dc2d3ca7);
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
/* -------------------------------------------------------------------------------------------------
|
|
61
|
+
* NavigationMenu
|
|
62
|
+
* -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$NAVIGATION_MENU_NAME = 'NavigationMenu';
|
|
63
|
+
const [$322c88a641701f3b$var$Collection, $322c88a641701f3b$var$useCollection, $322c88a641701f3b$var$createCollectionScope] = $yHMN2$createCollection($322c88a641701f3b$var$NAVIGATION_MENU_NAME);
|
|
64
|
+
const [$322c88a641701f3b$var$FocusGroupCollection, $322c88a641701f3b$var$useFocusGroupCollection, $322c88a641701f3b$var$createFocusGroupCollectionScope] = $yHMN2$createCollection($322c88a641701f3b$var$NAVIGATION_MENU_NAME);
|
|
65
|
+
const [$322c88a641701f3b$var$createNavigationMenuContext, $322c88a641701f3b$export$fb8ea5af8c9fcdf0] = $yHMN2$createContextScope($322c88a641701f3b$var$NAVIGATION_MENU_NAME, [
|
|
66
|
+
$322c88a641701f3b$var$createCollectionScope,
|
|
67
|
+
$322c88a641701f3b$var$createFocusGroupCollectionScope
|
|
68
|
+
]);
|
|
69
|
+
const [$322c88a641701f3b$var$NavigationMenuProviderImpl, $322c88a641701f3b$var$useNavigationMenuContext] = $322c88a641701f3b$var$createNavigationMenuContext($322c88a641701f3b$var$NAVIGATION_MENU_NAME);
|
|
70
|
+
const [$322c88a641701f3b$var$ViewportContentProvider, $322c88a641701f3b$var$useViewportContentContext] = $322c88a641701f3b$var$createNavigationMenuContext($322c88a641701f3b$var$NAVIGATION_MENU_NAME);
|
|
71
|
+
const $322c88a641701f3b$export$5b2278cf1e8bcae2 = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
|
|
72
|
+
const { __scopeNavigationMenu: __scopeNavigationMenu , value: value , onValueChange: onValueChange , defaultValue: defaultValue , orientation: orientation = 'horizontal' , dir: dir , ...NavigationMenuProps } = props;
|
|
73
|
+
const [navigationMenu, setNavigationMenu] = $yHMN2$useState(null);
|
|
74
|
+
const composedRef = $yHMN2$useComposedRefs(forwardedRef, (node)=>setNavigationMenu(node)
|
|
75
|
+
);
|
|
76
|
+
const direction = $yHMN2$useDirection(dir);
|
|
77
|
+
return /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$NavigationMenuProvider, {
|
|
78
|
+
scope: __scopeNavigationMenu,
|
|
79
|
+
isRootMenu: true,
|
|
80
|
+
value: value,
|
|
81
|
+
onValueChange: onValueChange,
|
|
82
|
+
defaultValue: defaultValue,
|
|
83
|
+
dir: direction,
|
|
84
|
+
orientation: orientation,
|
|
85
|
+
rootNavigationMenu: navigationMenu
|
|
86
|
+
}, /*#__PURE__*/ $yHMN2$createElement($yHMN2$Primitive.nav, $yHMN2$babelruntimehelpersesmextends({
|
|
87
|
+
"aria-label": "Main",
|
|
88
|
+
"data-orientation": orientation,
|
|
89
|
+
dir: direction
|
|
90
|
+
}, NavigationMenuProps, {
|
|
91
|
+
ref: composedRef
|
|
92
|
+
})));
|
|
93
|
+
});
|
|
94
|
+
/*#__PURE__*/ Object.assign($322c88a641701f3b$export$5b2278cf1e8bcae2, {
|
|
95
|
+
displayName: $322c88a641701f3b$var$NAVIGATION_MENU_NAME
|
|
96
|
+
});
|
|
97
|
+
/* -------------------------------------------------------------------------------------------------
|
|
98
|
+
* NavigationMenuSub
|
|
99
|
+
* -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$SUB_NAME = 'NavigationMenuSub';
|
|
100
|
+
const $322c88a641701f3b$export$5958edd6c4ee7c79 = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
|
|
101
|
+
const { __scopeNavigationMenu: __scopeNavigationMenu , value: value , onValueChange: onValueChange , defaultValue: defaultValue , orientation: orientation = 'horizontal' , ...subProps } = props;
|
|
102
|
+
const context = $322c88a641701f3b$var$useNavigationMenuContext($322c88a641701f3b$var$SUB_NAME, __scopeNavigationMenu);
|
|
103
|
+
return /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$NavigationMenuProvider, {
|
|
104
|
+
scope: __scopeNavigationMenu,
|
|
105
|
+
isRootMenu: false,
|
|
106
|
+
value: value,
|
|
107
|
+
onValueChange: onValueChange,
|
|
108
|
+
defaultValue: defaultValue,
|
|
109
|
+
dir: context.dir,
|
|
110
|
+
orientation: orientation,
|
|
111
|
+
rootNavigationMenu: context.rootNavigationMenu
|
|
112
|
+
}, /*#__PURE__*/ $yHMN2$createElement($yHMN2$Primitive.div, $yHMN2$babelruntimehelpersesmextends({
|
|
113
|
+
"data-orientation": orientation
|
|
114
|
+
}, subProps, {
|
|
115
|
+
ref: forwardedRef
|
|
116
|
+
})));
|
|
117
|
+
});
|
|
118
|
+
/*#__PURE__*/ Object.assign($322c88a641701f3b$export$5958edd6c4ee7c79, {
|
|
119
|
+
displayName: $322c88a641701f3b$var$SUB_NAME
|
|
120
|
+
});
|
|
121
|
+
/* -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$NavigationMenuProvider = (props)=>{
|
|
122
|
+
const { scope: scope , isRootMenu: isRootMenu , rootNavigationMenu: rootNavigationMenu , value: valueProp , onValueChange: onValueChange , defaultValue: defaultValue , dir: dir , orientation: orientation , children: children } = props;
|
|
123
|
+
const [viewport, setViewport] = $yHMN2$useState(null);
|
|
124
|
+
const [viewportContent, setViewportContent] = $yHMN2$useState(new Map());
|
|
125
|
+
const [indicatorTrack, setIndicatorTrack] = $yHMN2$useState(null);
|
|
126
|
+
const closeTimerRef = $yHMN2$useRef(0);
|
|
127
|
+
const [value = '', setValue] = $yHMN2$useControllableState({
|
|
128
|
+
prop: valueProp,
|
|
129
|
+
onChange: onValueChange,
|
|
130
|
+
defaultProp: defaultValue
|
|
131
|
+
});
|
|
132
|
+
$yHMN2$useEffect(()=>{
|
|
133
|
+
return ()=>window.clearTimeout(closeTimerRef.current)
|
|
134
|
+
;
|
|
135
|
+
}, [
|
|
136
|
+
closeTimerRef
|
|
137
|
+
]);
|
|
138
|
+
return /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$NavigationMenuProviderImpl, {
|
|
139
|
+
scope: scope,
|
|
140
|
+
isRootMenu: isRootMenu,
|
|
141
|
+
rootNavigationMenu: rootNavigationMenu,
|
|
142
|
+
value: value,
|
|
143
|
+
previousValue: $yHMN2$usePrevious(value),
|
|
144
|
+
baseId: $yHMN2$useId(),
|
|
145
|
+
dir: dir,
|
|
146
|
+
orientation: orientation,
|
|
147
|
+
viewport: viewport,
|
|
148
|
+
onViewportChange: setViewport,
|
|
149
|
+
indicatorTrack: indicatorTrack,
|
|
150
|
+
onIndicatorTrackChange: setIndicatorTrack,
|
|
151
|
+
onItemOver: $yHMN2$useCallback((itemValue)=>{
|
|
152
|
+
if (isRootMenu) window.clearTimeout(closeTimerRef.current);
|
|
153
|
+
setValue(itemValue);
|
|
154
|
+
}, [
|
|
155
|
+
setValue,
|
|
156
|
+
isRootMenu
|
|
157
|
+
]),
|
|
158
|
+
onItemLeave: $yHMN2$useCallback(()=>{
|
|
159
|
+
if (isRootMenu) {
|
|
160
|
+
window.clearTimeout(closeTimerRef.current);
|
|
161
|
+
closeTimerRef.current = window.setTimeout(()=>setValue('')
|
|
162
|
+
, 150);
|
|
163
|
+
}
|
|
164
|
+
}, [
|
|
165
|
+
setValue,
|
|
166
|
+
isRootMenu
|
|
167
|
+
]),
|
|
168
|
+
onItemSelect: $yHMN2$useCallback((itemValue)=>{
|
|
169
|
+
setValue((prevValue)=>{
|
|
170
|
+
return isRootMenu ? prevValue === itemValue ? '' : itemValue : itemValue;
|
|
171
|
+
});
|
|
172
|
+
}, [
|
|
173
|
+
setValue,
|
|
174
|
+
isRootMenu
|
|
175
|
+
]),
|
|
176
|
+
onItemDismiss: $yHMN2$useCallback(()=>setValue('')
|
|
177
|
+
, [
|
|
178
|
+
setValue
|
|
179
|
+
]),
|
|
180
|
+
onViewportContentChange: $yHMN2$useCallback((contentValue, contentData)=>{
|
|
181
|
+
setViewportContent((prevContent)=>{
|
|
182
|
+
prevContent.set(contentValue, contentData);
|
|
183
|
+
return new Map(prevContent);
|
|
184
|
+
});
|
|
185
|
+
}, []),
|
|
186
|
+
onViewportContentRemove: $yHMN2$useCallback((contentValue)=>{
|
|
187
|
+
setViewportContent((prevContent)=>{
|
|
188
|
+
if (!prevContent.has(contentValue)) return prevContent;
|
|
189
|
+
prevContent.delete(contentValue);
|
|
190
|
+
return new Map(prevContent);
|
|
191
|
+
});
|
|
192
|
+
}, [])
|
|
193
|
+
}, /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$Collection.Provider, {
|
|
194
|
+
scope: scope
|
|
195
|
+
}, /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$ViewportContentProvider, {
|
|
196
|
+
scope: scope,
|
|
197
|
+
items: viewportContent
|
|
198
|
+
}, children)));
|
|
199
|
+
};
|
|
200
|
+
/* -------------------------------------------------------------------------------------------------
|
|
201
|
+
* NavigationMenuList
|
|
202
|
+
* -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$LIST_NAME = 'NavigationMenuList';
|
|
203
|
+
const $322c88a641701f3b$export$c361068a95fd2286 = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
|
|
204
|
+
const { __scopeNavigationMenu: __scopeNavigationMenu , ...listProps } = props;
|
|
205
|
+
const context = $322c88a641701f3b$var$useNavigationMenuContext($322c88a641701f3b$var$LIST_NAME, __scopeNavigationMenu);
|
|
206
|
+
const list = /*#__PURE__*/ $yHMN2$createElement($yHMN2$Primitive.ul, $yHMN2$babelruntimehelpersesmextends({
|
|
207
|
+
"data-orientation": context.orientation
|
|
208
|
+
}, listProps, {
|
|
209
|
+
ref: forwardedRef
|
|
210
|
+
}));
|
|
211
|
+
return /*#__PURE__*/ $yHMN2$createElement($yHMN2$Primitive.div, {
|
|
212
|
+
style: {
|
|
213
|
+
position: 'relative'
|
|
214
|
+
},
|
|
215
|
+
ref: context.onIndicatorTrackChange
|
|
216
|
+
}, /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$Collection.Slot, {
|
|
217
|
+
scope: __scopeNavigationMenu
|
|
218
|
+
}, context.isRootMenu ? /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$FocusGroup, {
|
|
219
|
+
asChild: true
|
|
220
|
+
}, list) : list));
|
|
221
|
+
});
|
|
222
|
+
/*#__PURE__*/ Object.assign($322c88a641701f3b$export$c361068a95fd2286, {
|
|
223
|
+
displayName: $322c88a641701f3b$var$LIST_NAME
|
|
224
|
+
});
|
|
225
|
+
/* -------------------------------------------------------------------------------------------------
|
|
226
|
+
* NavigationMenuItem
|
|
227
|
+
* -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$ITEM_NAME = 'NavigationMenuItem';
|
|
228
|
+
const [$322c88a641701f3b$var$NavigationMenuItemContextProvider, $322c88a641701f3b$var$useNavigationMenuItemContext] = $322c88a641701f3b$var$createNavigationMenuContext($322c88a641701f3b$var$ITEM_NAME);
|
|
229
|
+
const $322c88a641701f3b$export$ffdbb83a2de845c2 = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
|
|
230
|
+
const { __scopeNavigationMenu: __scopeNavigationMenu , value: valueProp , ...itemProps } = props;
|
|
231
|
+
const autoValue = $yHMN2$useId(); // We need to provide an initial deterministic value as `useId` will return
|
|
232
|
+
// empty string on the first render and we don't want to match our internal "closed" value.
|
|
233
|
+
const value = valueProp || autoValue || 'LEGACY_REACT_AUTO_VALUE';
|
|
234
|
+
const contentRef = $yHMN2$useRef(null);
|
|
235
|
+
const triggerRef = $yHMN2$useRef(null);
|
|
236
|
+
const focusProxyRef = $yHMN2$useRef(null);
|
|
237
|
+
const restoreContentTabOrderRef = $yHMN2$useRef(()=>{});
|
|
238
|
+
const handleContentEntry = $yHMN2$useCallback((side = 'start')=>{
|
|
239
|
+
if (contentRef.current) {
|
|
240
|
+
restoreContentTabOrderRef.current();
|
|
241
|
+
const candidates = $322c88a641701f3b$var$getTabbableCandidates(contentRef.current);
|
|
242
|
+
if (candidates.length) $322c88a641701f3b$var$focusFirst(side === 'start' ? candidates : candidates.reverse());
|
|
243
|
+
}
|
|
244
|
+
}, []);
|
|
245
|
+
const handleContentExit = $yHMN2$useCallback(()=>{
|
|
246
|
+
if (contentRef.current) {
|
|
247
|
+
const candidates = $322c88a641701f3b$var$getTabbableCandidates(contentRef.current);
|
|
248
|
+
if (candidates.length) restoreContentTabOrderRef.current = $322c88a641701f3b$var$removeFromTabOrder(candidates);
|
|
249
|
+
}
|
|
250
|
+
}, []);
|
|
251
|
+
return /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$NavigationMenuItemContextProvider, {
|
|
252
|
+
scope: __scopeNavigationMenu,
|
|
253
|
+
value: value,
|
|
254
|
+
triggerRef: triggerRef,
|
|
255
|
+
contentRef: contentRef,
|
|
256
|
+
focusProxyRef: focusProxyRef,
|
|
257
|
+
onEntryKeyDown: handleContentEntry,
|
|
258
|
+
onFocusProxyEnter: handleContentEntry,
|
|
259
|
+
onRootContentClose: handleContentExit,
|
|
260
|
+
onContentFocusOutside: handleContentExit
|
|
261
|
+
}, /*#__PURE__*/ $yHMN2$createElement($yHMN2$Primitive.li, $yHMN2$babelruntimehelpersesmextends({}, itemProps, {
|
|
262
|
+
ref: forwardedRef
|
|
263
|
+
})));
|
|
264
|
+
});
|
|
265
|
+
/*#__PURE__*/ Object.assign($322c88a641701f3b$export$ffdbb83a2de845c2, {
|
|
266
|
+
displayName: $322c88a641701f3b$var$ITEM_NAME
|
|
267
|
+
});
|
|
268
|
+
/* -------------------------------------------------------------------------------------------------
|
|
269
|
+
* NavigationMenuTrigger
|
|
270
|
+
* -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$TRIGGER_NAME = 'NavigationMenuTrigger';
|
|
271
|
+
const $322c88a641701f3b$export$37fe8002734d8f2 = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
|
|
272
|
+
const { __scopeNavigationMenu: __scopeNavigationMenu , disabled: disabled , ...triggerProps } = props;
|
|
273
|
+
const context = $322c88a641701f3b$var$useNavigationMenuContext($322c88a641701f3b$var$TRIGGER_NAME, props.__scopeNavigationMenu);
|
|
274
|
+
const itemContext = $322c88a641701f3b$var$useNavigationMenuItemContext($322c88a641701f3b$var$TRIGGER_NAME, props.__scopeNavigationMenu);
|
|
275
|
+
const ref = $yHMN2$useRef(null);
|
|
276
|
+
const composedRefs = $yHMN2$useComposedRefs(ref, itemContext.triggerRef, forwardedRef);
|
|
277
|
+
const triggerId = $322c88a641701f3b$var$makeTriggerId(context.baseId, itemContext.value);
|
|
278
|
+
const contentId = $322c88a641701f3b$var$makeContentId(context.baseId, itemContext.value);
|
|
279
|
+
const wasClickCloseRef = $yHMN2$useRef(false);
|
|
280
|
+
const open = itemContext.value === context.value;
|
|
281
|
+
return /*#__PURE__*/ $yHMN2$createElement($yHMN2$Fragment, null, /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$Collection.ItemSlot, {
|
|
282
|
+
scope: __scopeNavigationMenu,
|
|
283
|
+
value: itemContext.value
|
|
284
|
+
}, /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$FocusGroupItem, {
|
|
285
|
+
asChild: true
|
|
286
|
+
}, /*#__PURE__*/ $yHMN2$createElement($yHMN2$Primitive.button, $yHMN2$babelruntimehelpersesmextends({
|
|
287
|
+
id: triggerId,
|
|
288
|
+
disabled: disabled,
|
|
289
|
+
"data-disabled": disabled ? '' : undefined,
|
|
290
|
+
"data-state": $322c88a641701f3b$var$getOpenState(open),
|
|
291
|
+
"aria-expanded": open,
|
|
292
|
+
"aria-controls": contentId
|
|
293
|
+
}, triggerProps, {
|
|
294
|
+
ref: composedRefs,
|
|
295
|
+
onPointerEnter: $yHMN2$composeEventHandlers(props.onPointerEnter, ()=>{
|
|
296
|
+
wasClickCloseRef.current = false;
|
|
297
|
+
}),
|
|
298
|
+
onPointerMove: $yHMN2$composeEventHandlers(props.onPointerMove, $322c88a641701f3b$var$whenMouse(()=>{
|
|
299
|
+
if (disabled || wasClickCloseRef.current) return;
|
|
300
|
+
context.onItemOver(itemContext.value);
|
|
301
|
+
})),
|
|
302
|
+
onPointerLeave: $yHMN2$composeEventHandlers(props.onPointerLeave, $322c88a641701f3b$var$whenMouse(()=>{
|
|
303
|
+
if (disabled) return;
|
|
304
|
+
context.onItemLeave();
|
|
305
|
+
})),
|
|
306
|
+
onClick: $yHMN2$composeEventHandlers(props.onClick, ()=>{
|
|
307
|
+
context.onItemSelect(itemContext.value);
|
|
308
|
+
wasClickCloseRef.current = open;
|
|
309
|
+
}),
|
|
310
|
+
onKeyDown: $yHMN2$composeEventHandlers(props.onKeyDown, (event)=>{
|
|
311
|
+
const verticalEntryKey = context.dir === 'rtl' ? 'ArrowLeft' : 'ArrowRight';
|
|
312
|
+
const entryKey = {
|
|
313
|
+
horizontal: 'ArrowDown',
|
|
314
|
+
vertical: verticalEntryKey
|
|
315
|
+
}[context.orientation];
|
|
316
|
+
if (open && event.key === entryKey) {
|
|
317
|
+
itemContext.onEntryKeyDown(); // Prevent FocusGroupItem from handling the event
|
|
318
|
+
event.preventDefault();
|
|
319
|
+
}
|
|
320
|
+
})
|
|
321
|
+
})))), open && /*#__PURE__*/ $yHMN2$createElement($yHMN2$Fragment, null, /*#__PURE__*/ $yHMN2$createElement($yHMN2$Root, {
|
|
322
|
+
"aria-hidden": true,
|
|
323
|
+
tabIndex: 0,
|
|
324
|
+
ref: itemContext.focusProxyRef,
|
|
325
|
+
onFocus: (event)=>{
|
|
326
|
+
const content = itemContext.contentRef.current;
|
|
327
|
+
const prevFocusedElement = event.relatedTarget;
|
|
328
|
+
const wasTriggerFocused = prevFocusedElement === ref.current;
|
|
329
|
+
const wasFocusFromContent = content === null || content === void 0 ? void 0 : content.contains(prevFocusedElement);
|
|
330
|
+
if (wasTriggerFocused || !wasFocusFromContent) itemContext.onFocusProxyEnter(wasTriggerFocused ? 'start' : 'end');
|
|
331
|
+
}
|
|
332
|
+
}), context.viewport && /*#__PURE__*/ $yHMN2$createElement("span", {
|
|
333
|
+
"aria-owns": contentId
|
|
334
|
+
})));
|
|
335
|
+
});
|
|
336
|
+
/*#__PURE__*/ Object.assign($322c88a641701f3b$export$37fe8002734d8f2, {
|
|
337
|
+
displayName: $322c88a641701f3b$var$TRIGGER_NAME
|
|
338
|
+
});
|
|
339
|
+
/* -------------------------------------------------------------------------------------------------
|
|
340
|
+
* NavigationMenuLink
|
|
341
|
+
* -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$LINK_NAME = 'NavigationMenuLink';
|
|
342
|
+
const $322c88a641701f3b$export$6893bf21536567da = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
|
|
343
|
+
const { __scopeNavigationMenu: __scopeNavigationMenu , active: active , ...linkProps } = props;
|
|
344
|
+
return /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$FocusGroupItem, {
|
|
345
|
+
asChild: true
|
|
346
|
+
}, /*#__PURE__*/ $yHMN2$createElement($yHMN2$Primitive.a, $yHMN2$babelruntimehelpersesmextends({
|
|
347
|
+
"data-active": active ? '' : undefined,
|
|
348
|
+
"aria-current": active ? 'page' : undefined
|
|
349
|
+
}, linkProps, {
|
|
350
|
+
ref: forwardedRef
|
|
351
|
+
})));
|
|
352
|
+
});
|
|
353
|
+
/*#__PURE__*/ Object.assign($322c88a641701f3b$export$6893bf21536567da, {
|
|
354
|
+
displayName: $322c88a641701f3b$var$LINK_NAME
|
|
355
|
+
});
|
|
356
|
+
/* -------------------------------------------------------------------------------------------------
|
|
357
|
+
* NavigationMenuIndicator
|
|
358
|
+
* -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$INDICATOR_NAME = 'NavigationMenuIndicator';
|
|
359
|
+
const $322c88a641701f3b$export$8ddb526647c0d8fb = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
|
|
360
|
+
const { forceMount: forceMount , ...indicatorProps } = props;
|
|
361
|
+
const context = $322c88a641701f3b$var$useNavigationMenuContext($322c88a641701f3b$var$INDICATOR_NAME, props.__scopeNavigationMenu);
|
|
362
|
+
const isVisible = Boolean(context.value);
|
|
363
|
+
return context.indicatorTrack ? /*#__PURE__*/ $yHMN2$reactdom.createPortal(/*#__PURE__*/ $yHMN2$createElement($yHMN2$Presence, {
|
|
364
|
+
present: forceMount || isVisible
|
|
365
|
+
}, /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$NavigationMenuIndicatorImpl, $yHMN2$babelruntimehelpersesmextends({}, indicatorProps, {
|
|
366
|
+
ref: forwardedRef
|
|
367
|
+
}))), context.indicatorTrack) : null;
|
|
368
|
+
});
|
|
369
|
+
/*#__PURE__*/ Object.assign($322c88a641701f3b$export$8ddb526647c0d8fb, {
|
|
370
|
+
displayName: $322c88a641701f3b$var$INDICATOR_NAME
|
|
371
|
+
});
|
|
372
|
+
const $322c88a641701f3b$var$NavigationMenuIndicatorImpl = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
|
|
373
|
+
const { __scopeNavigationMenu: __scopeNavigationMenu , ...indicatorProps } = props;
|
|
374
|
+
const context = $322c88a641701f3b$var$useNavigationMenuContext($322c88a641701f3b$var$INDICATOR_NAME, __scopeNavigationMenu);
|
|
375
|
+
const getItems = $322c88a641701f3b$var$useCollection(__scopeNavigationMenu);
|
|
376
|
+
const [activeTrigger, setActiveTrigger] = $yHMN2$useState(null);
|
|
377
|
+
const [position, setPosition] = $yHMN2$useState(null);
|
|
378
|
+
const isHorizontal = context.orientation === 'horizontal';
|
|
379
|
+
const isVisible = Boolean(context.value);
|
|
380
|
+
$yHMN2$useEffect(()=>{
|
|
381
|
+
var _items$find;
|
|
382
|
+
const items = getItems();
|
|
383
|
+
const triggerNode = (_items$find = items.find((item)=>item.value === context.value
|
|
384
|
+
)) === null || _items$find === void 0 ? void 0 : _items$find.ref.current;
|
|
385
|
+
if (triggerNode) setActiveTrigger(triggerNode);
|
|
386
|
+
}, [
|
|
387
|
+
getItems,
|
|
388
|
+
context.value
|
|
389
|
+
]);
|
|
390
|
+
/**
|
|
391
|
+
* Update position when the indicator or parent track size changes
|
|
392
|
+
*/ const handlePositionChange = ()=>{
|
|
393
|
+
if (activeTrigger) setPosition({
|
|
394
|
+
size: isHorizontal ? activeTrigger.offsetWidth : activeTrigger.offsetHeight,
|
|
395
|
+
offset: isHorizontal ? activeTrigger.offsetLeft : activeTrigger.offsetTop
|
|
396
|
+
});
|
|
397
|
+
};
|
|
398
|
+
$322c88a641701f3b$var$useResizeObserver(activeTrigger, handlePositionChange);
|
|
399
|
+
$322c88a641701f3b$var$useResizeObserver(context.indicatorTrack, handlePositionChange); // We need to wait for the indicator position to be available before rendering to
|
|
400
|
+
// snap immediately into position rather than transitioning from initial
|
|
401
|
+
return position ? /*#__PURE__*/ $yHMN2$createElement($yHMN2$Primitive.div, $yHMN2$babelruntimehelpersesmextends({
|
|
402
|
+
"aria-hidden": true,
|
|
403
|
+
"data-state": isVisible ? 'visible' : 'hidden',
|
|
404
|
+
"data-orientation": context.orientation
|
|
405
|
+
}, indicatorProps, {
|
|
406
|
+
ref: forwardedRef,
|
|
407
|
+
style: {
|
|
408
|
+
position: 'absolute',
|
|
409
|
+
...isHorizontal ? {
|
|
410
|
+
left: 0,
|
|
411
|
+
width: position.size + 'px',
|
|
412
|
+
transform: `translateX(${position.offset}px)`
|
|
413
|
+
} : {
|
|
414
|
+
top: 0,
|
|
415
|
+
height: position.size + 'px',
|
|
416
|
+
transform: `translateY(${position.offset}px)`
|
|
417
|
+
},
|
|
418
|
+
...indicatorProps.style
|
|
419
|
+
}
|
|
420
|
+
})) : null;
|
|
421
|
+
});
|
|
422
|
+
/* -------------------------------------------------------------------------------------------------
|
|
423
|
+
* NavigationMenuContent
|
|
424
|
+
* -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$CONTENT_NAME = 'NavigationMenuContent';
|
|
425
|
+
const $322c88a641701f3b$export$38e00e996c2f93f7 = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
|
|
426
|
+
const { forceMount: forceMount , ...contentProps } = props;
|
|
427
|
+
const context = $322c88a641701f3b$var$useNavigationMenuContext($322c88a641701f3b$var$CONTENT_NAME, props.__scopeNavigationMenu);
|
|
428
|
+
const itemContext = $322c88a641701f3b$var$useNavigationMenuItemContext($322c88a641701f3b$var$CONTENT_NAME, props.__scopeNavigationMenu);
|
|
429
|
+
const composedRefs = $yHMN2$useComposedRefs(itemContext.contentRef, forwardedRef);
|
|
430
|
+
const open = itemContext.value === context.value;
|
|
431
|
+
const commonProps = {
|
|
432
|
+
value: itemContext.value,
|
|
433
|
+
triggerRef: itemContext.triggerRef,
|
|
434
|
+
focusProxyRef: itemContext.focusProxyRef,
|
|
435
|
+
onContentFocusOutside: itemContext.onContentFocusOutside,
|
|
436
|
+
onRootContentClose: itemContext.onRootContentClose,
|
|
437
|
+
...contentProps
|
|
438
|
+
};
|
|
439
|
+
return !context.viewport ? /*#__PURE__*/ $yHMN2$createElement($yHMN2$Presence, {
|
|
440
|
+
present: forceMount || open
|
|
441
|
+
}, /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$NavigationMenuContentImpl, $yHMN2$babelruntimehelpersesmextends({
|
|
442
|
+
"data-state": $322c88a641701f3b$var$getOpenState(open)
|
|
443
|
+
}, commonProps, {
|
|
444
|
+
ref: composedRefs,
|
|
445
|
+
onPointerEnter: $yHMN2$composeEventHandlers(props.onPointerEnter, ()=>{
|
|
446
|
+
context.onItemOver(itemContext.value);
|
|
447
|
+
}),
|
|
448
|
+
onPointerLeave: $yHMN2$composeEventHandlers(props.onPointerLeave, $322c88a641701f3b$var$whenMouse(context.onItemLeave)),
|
|
449
|
+
style: {
|
|
450
|
+
// Prevent interaction when animating out
|
|
451
|
+
pointerEvents: !open && context.isRootMenu ? 'none' : undefined,
|
|
452
|
+
...commonProps.style
|
|
453
|
+
}
|
|
454
|
+
}))) : /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$ViewportContentMounter, $yHMN2$babelruntimehelpersesmextends({
|
|
455
|
+
forceMount: forceMount
|
|
456
|
+
}, commonProps, {
|
|
457
|
+
ref: composedRefs
|
|
458
|
+
}));
|
|
459
|
+
});
|
|
460
|
+
/*#__PURE__*/ Object.assign($322c88a641701f3b$export$38e00e996c2f93f7, {
|
|
461
|
+
displayName: $322c88a641701f3b$var$CONTENT_NAME
|
|
462
|
+
});
|
|
463
|
+
/* -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$ViewportContentMounter = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
|
|
464
|
+
const context = $322c88a641701f3b$var$useNavigationMenuContext($322c88a641701f3b$var$CONTENT_NAME, props.__scopeNavigationMenu);
|
|
465
|
+
const { onViewportContentChange: onViewportContentChange , onViewportContentRemove: onViewportContentRemove } = context;
|
|
466
|
+
$yHMN2$useLayoutEffect(()=>{
|
|
467
|
+
onViewportContentChange(props.value, {
|
|
468
|
+
ref: forwardedRef,
|
|
469
|
+
...props
|
|
470
|
+
});
|
|
471
|
+
}, [
|
|
472
|
+
props,
|
|
473
|
+
forwardedRef,
|
|
474
|
+
onViewportContentChange
|
|
475
|
+
]);
|
|
476
|
+
$yHMN2$useLayoutEffect(()=>{
|
|
477
|
+
return ()=>onViewportContentRemove(props.value)
|
|
478
|
+
;
|
|
479
|
+
}, [
|
|
480
|
+
props.value,
|
|
481
|
+
onViewportContentRemove
|
|
482
|
+
]); // Content is proxied into the viewport
|
|
483
|
+
return null;
|
|
484
|
+
});
|
|
485
|
+
/* -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$CONTENT_DISMISS = 'navigationMenu.contentDismiss';
|
|
486
|
+
const $322c88a641701f3b$var$NavigationMenuContentImpl = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
|
|
487
|
+
const { __scopeNavigationMenu: __scopeNavigationMenu , value: value , triggerRef: triggerRef , focusProxyRef: focusProxyRef , onRootContentClose: onRootContentClose , onContentFocusOutside: onContentFocusOutside , ...contentProps } = props;
|
|
488
|
+
const context = $322c88a641701f3b$var$useNavigationMenuContext($322c88a641701f3b$var$CONTENT_NAME, __scopeNavigationMenu);
|
|
489
|
+
const ref = $yHMN2$useRef(null);
|
|
490
|
+
const composedRefs = $yHMN2$useComposedRefs(ref, forwardedRef);
|
|
491
|
+
const triggerId = $322c88a641701f3b$var$makeTriggerId(context.baseId, value);
|
|
492
|
+
const contentId = $322c88a641701f3b$var$makeContentId(context.baseId, value);
|
|
493
|
+
const getItems = $322c88a641701f3b$var$useCollection(__scopeNavigationMenu);
|
|
494
|
+
const prevMotionAttributeRef = $yHMN2$useRef(null);
|
|
495
|
+
const { onItemDismiss: onItemDismiss } = context;
|
|
496
|
+
$yHMN2$useEffect(()=>{
|
|
497
|
+
const content = ref.current; // Bubble dismiss to the root content node and focus its trigger
|
|
498
|
+
if (context.isRootMenu && content) {
|
|
499
|
+
const handleClose = ()=>{
|
|
500
|
+
var _triggerRef$current;
|
|
501
|
+
onItemDismiss();
|
|
502
|
+
onRootContentClose();
|
|
503
|
+
if (content.contains(document.activeElement)) (_triggerRef$current = triggerRef.current) === null || _triggerRef$current === void 0 || _triggerRef$current.focus();
|
|
504
|
+
};
|
|
505
|
+
content.addEventListener($322c88a641701f3b$var$CONTENT_DISMISS, handleClose);
|
|
506
|
+
return ()=>content.removeEventListener($322c88a641701f3b$var$CONTENT_DISMISS, handleClose)
|
|
507
|
+
;
|
|
508
|
+
}
|
|
509
|
+
}, [
|
|
510
|
+
context.isRootMenu,
|
|
511
|
+
props.value,
|
|
512
|
+
triggerRef,
|
|
513
|
+
onItemDismiss,
|
|
514
|
+
onRootContentClose
|
|
515
|
+
]);
|
|
516
|
+
const motionAttribute = $yHMN2$useMemo(()=>{
|
|
517
|
+
const items = getItems();
|
|
518
|
+
const values = items.map((item)=>item.value
|
|
519
|
+
);
|
|
520
|
+
if (context.dir === 'rtl') values.reverse();
|
|
521
|
+
const index = values.indexOf(context.value);
|
|
522
|
+
const prevIndex = values.indexOf(context.previousValue);
|
|
523
|
+
const isSelected = value === context.value;
|
|
524
|
+
const wasSelected = prevIndex === values.indexOf(value); // We only want to update selected and the last selected content
|
|
525
|
+
// this avoids animations being interrupted outside of that range
|
|
526
|
+
if (!isSelected && !wasSelected) return prevMotionAttributeRef.current;
|
|
527
|
+
const attribute = (()=>{
|
|
528
|
+
// Don't provide a direction on the initial open
|
|
529
|
+
if (index !== prevIndex) {
|
|
530
|
+
// If we're moving to this item from another
|
|
531
|
+
if (isSelected && prevIndex !== -1) return index > prevIndex ? 'from-end' : 'from-start'; // If we're leaving this item for another
|
|
532
|
+
if (wasSelected && index !== -1) return index > prevIndex ? 'to-start' : 'to-end';
|
|
533
|
+
} // Otherwise we're entering from closed or leaving the list
|
|
534
|
+
// entirely and should not animate in any direction
|
|
535
|
+
return null;
|
|
536
|
+
})();
|
|
537
|
+
prevMotionAttributeRef.current = attribute;
|
|
538
|
+
return attribute;
|
|
539
|
+
}, [
|
|
540
|
+
context.previousValue,
|
|
541
|
+
context.value,
|
|
542
|
+
context.dir,
|
|
543
|
+
getItems,
|
|
544
|
+
value
|
|
545
|
+
]);
|
|
546
|
+
return /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$FocusGroup, {
|
|
547
|
+
asChild: true
|
|
548
|
+
}, /*#__PURE__*/ $yHMN2$createElement($yHMN2$DismissableLayer, $yHMN2$babelruntimehelpersesmextends({
|
|
549
|
+
id: contentId,
|
|
550
|
+
"aria-labelledby": triggerId,
|
|
551
|
+
"data-motion": motionAttribute,
|
|
552
|
+
"data-orientation": context.orientation
|
|
553
|
+
}, contentProps, {
|
|
554
|
+
ref: composedRefs,
|
|
555
|
+
onDismiss: ()=>{
|
|
556
|
+
var _ref$current;
|
|
557
|
+
const contentDismissEvent = new Event($322c88a641701f3b$var$CONTENT_DISMISS, {
|
|
558
|
+
bubbles: true,
|
|
559
|
+
cancelable: true
|
|
560
|
+
});
|
|
561
|
+
(_ref$current = ref.current) === null || _ref$current === void 0 || _ref$current.dispatchEvent(contentDismissEvent);
|
|
562
|
+
},
|
|
563
|
+
onFocusOutside: $yHMN2$composeEventHandlers(props.onFocusOutside, (event)=>{
|
|
564
|
+
var _context$rootNavigati;
|
|
565
|
+
onContentFocusOutside();
|
|
566
|
+
const target = event.target; // Only dismiss content when focus moves outside of the menu
|
|
567
|
+
if ((_context$rootNavigati = context.rootNavigationMenu) !== null && _context$rootNavigati !== void 0 && _context$rootNavigati.contains(target)) event.preventDefault();
|
|
568
|
+
}),
|
|
569
|
+
onPointerDownOutside: $yHMN2$composeEventHandlers(props.onPointerDownOutside, (event)=>{
|
|
570
|
+
var _context$viewport;
|
|
571
|
+
const target = event.target;
|
|
572
|
+
const isTrigger = getItems().some((item)=>{
|
|
573
|
+
var _item$ref$current;
|
|
574
|
+
return (_item$ref$current = item.ref.current) === null || _item$ref$current === void 0 ? void 0 : _item$ref$current.contains(target);
|
|
575
|
+
});
|
|
576
|
+
const isRootViewport = context.isRootMenu && ((_context$viewport = context.viewport) === null || _context$viewport === void 0 ? void 0 : _context$viewport.contains(target));
|
|
577
|
+
if (isTrigger || isRootViewport || !context.isRootMenu) event.preventDefault();
|
|
578
|
+
}),
|
|
579
|
+
onKeyDown: $yHMN2$composeEventHandlers(props.onKeyDown, (event)=>{
|
|
580
|
+
const isMetaKey = event.altKey || event.ctrlKey || event.metaKey;
|
|
581
|
+
const isTabKey = event.key === 'Tab' && !isMetaKey;
|
|
582
|
+
if (isTabKey) {
|
|
583
|
+
const candidates = $322c88a641701f3b$var$getTabbableCandidates(event.currentTarget);
|
|
584
|
+
const focusedElement = document.activeElement;
|
|
585
|
+
const index = candidates.findIndex((candidate)=>candidate === focusedElement
|
|
586
|
+
);
|
|
587
|
+
const isMovingBackwards = event.shiftKey;
|
|
588
|
+
const nextCandidates = isMovingBackwards ? candidates.slice(0, index).reverse() : candidates.slice(index + 1, candidates.length);
|
|
589
|
+
if ($322c88a641701f3b$var$focusFirst(nextCandidates)) // prevent browser tab keydown because we've handled focus
|
|
590
|
+
event.preventDefault();
|
|
591
|
+
else {
|
|
592
|
+
var _focusProxyRef$curren;
|
|
593
|
+
// If we can't focus that means we're at the edges
|
|
594
|
+
// so focus the proxy and let browser handle
|
|
595
|
+
// tab/shift+tab keypress on the proxy instead
|
|
596
|
+
(_focusProxyRef$curren = focusProxyRef.current) === null || _focusProxyRef$curren === void 0 || _focusProxyRef$curren.focus();
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
})
|
|
600
|
+
})));
|
|
601
|
+
});
|
|
602
|
+
/* -------------------------------------------------------------------------------------------------
|
|
603
|
+
* NavigationMenuViewport
|
|
604
|
+
* -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$VIEWPORT_NAME = 'NavigationMenuViewport';
|
|
605
|
+
const $322c88a641701f3b$export$ee880b97cc6d44a5 = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
|
|
606
|
+
const { forceMount: forceMount , ...viewportProps } = props;
|
|
607
|
+
const context = $322c88a641701f3b$var$useNavigationMenuContext($322c88a641701f3b$var$VIEWPORT_NAME, props.__scopeNavigationMenu);
|
|
608
|
+
const open = Boolean(context.value);
|
|
609
|
+
return /*#__PURE__*/ $yHMN2$createElement($yHMN2$Presence, {
|
|
610
|
+
present: forceMount || open
|
|
611
|
+
}, /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$NavigationMenuViewportImpl, $yHMN2$babelruntimehelpersesmextends({}, viewportProps, {
|
|
612
|
+
ref: forwardedRef
|
|
613
|
+
})));
|
|
614
|
+
});
|
|
615
|
+
/*#__PURE__*/ Object.assign($322c88a641701f3b$export$ee880b97cc6d44a5, {
|
|
616
|
+
displayName: $322c88a641701f3b$var$VIEWPORT_NAME
|
|
617
|
+
});
|
|
618
|
+
/* -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$NavigationMenuViewportImpl = /*#__PURE__*/ $yHMN2$forwardRef((props1, forwardedRef)=>{
|
|
619
|
+
const { __scopeNavigationMenu: __scopeNavigationMenu , children: children , ...viewportImplProps } = props1;
|
|
620
|
+
const context = $322c88a641701f3b$var$useNavigationMenuContext($322c88a641701f3b$var$VIEWPORT_NAME, __scopeNavigationMenu);
|
|
621
|
+
const composedRefs = $yHMN2$useComposedRefs(forwardedRef, context.onViewportChange);
|
|
622
|
+
const viewportContentContext = $322c88a641701f3b$var$useViewportContentContext($322c88a641701f3b$var$CONTENT_NAME, props1.__scopeNavigationMenu);
|
|
623
|
+
const [size, setSize] = $yHMN2$useState(null);
|
|
624
|
+
const [content, setContent] = $yHMN2$useState(null);
|
|
625
|
+
const viewportWidth = size ? (size === null || size === void 0 ? void 0 : size.width) + 'px' : undefined;
|
|
626
|
+
const viewportHeight = size ? (size === null || size === void 0 ? void 0 : size.height) + 'px' : undefined;
|
|
627
|
+
const open = Boolean(context.value); // We persist the last active content value as the viewport may be animating out
|
|
628
|
+
// and we want the content to remain mounted for the lifecycle of the viewport.
|
|
629
|
+
const activeContentValue = open ? context.value : context.previousValue;
|
|
630
|
+
/**
|
|
631
|
+
* Update viewport size to match the active content node.
|
|
632
|
+
* We prefer offset dimensions over `getBoundingClientRect` as the latter respects CSS transform.
|
|
633
|
+
* For example, if content animates in from `scale(0.5)` the dimensions would be anything
|
|
634
|
+
* from `0.5` to `1` of the intended size.
|
|
635
|
+
*/ const handleSizeChange = ()=>{
|
|
636
|
+
if (content) setSize({
|
|
637
|
+
width: content.offsetWidth,
|
|
638
|
+
height: content.offsetHeight
|
|
639
|
+
});
|
|
640
|
+
};
|
|
641
|
+
$322c88a641701f3b$var$useResizeObserver(content, handleSizeChange);
|
|
642
|
+
return /*#__PURE__*/ $yHMN2$createElement($yHMN2$Primitive.div, $yHMN2$babelruntimehelpersesmextends({
|
|
643
|
+
"data-state": $322c88a641701f3b$var$getOpenState(open),
|
|
644
|
+
"data-orientation": context.orientation
|
|
645
|
+
}, viewportImplProps, {
|
|
646
|
+
ref: composedRefs,
|
|
647
|
+
style: {
|
|
648
|
+
// Prevent interaction when animating out
|
|
649
|
+
pointerEvents: !open && context.isRootMenu ? 'none' : undefined,
|
|
650
|
+
['--radix-navigation-menu-viewport-width']: viewportWidth,
|
|
651
|
+
['--radix-navigation-menu-viewport-height']: viewportHeight,
|
|
652
|
+
...viewportImplProps.style
|
|
653
|
+
},
|
|
654
|
+
onPointerEnter: $yHMN2$composeEventHandlers(props1.onPointerEnter, ()=>{
|
|
655
|
+
context.onItemOver(activeContentValue);
|
|
656
|
+
}),
|
|
657
|
+
onPointerLeave: $yHMN2$composeEventHandlers(props1.onPointerLeave, $322c88a641701f3b$var$whenMouse(context.onItemLeave))
|
|
658
|
+
}), Array.from(viewportContentContext.items).map(([value, { ref: ref , forceMount: forceMount , ...props }])=>{
|
|
659
|
+
const isActive = activeContentValue === value;
|
|
660
|
+
return /*#__PURE__*/ $yHMN2$createElement($yHMN2$Presence, {
|
|
661
|
+
key: value,
|
|
662
|
+
present: forceMount || isActive
|
|
663
|
+
}, /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$NavigationMenuContentImpl, $yHMN2$babelruntimehelpersesmextends({}, props, {
|
|
664
|
+
ref: $yHMN2$composeRefs(ref, (node)=>{
|
|
665
|
+
// We only want to update the stored node when another is available
|
|
666
|
+
// as we need to smoothly transition between them.
|
|
667
|
+
if (isActive && node) setContent(node);
|
|
668
|
+
})
|
|
669
|
+
})));
|
|
670
|
+
}));
|
|
671
|
+
});
|
|
672
|
+
/* -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$FOCUS_GROUP_NAME = 'FocusGroup';
|
|
673
|
+
const $322c88a641701f3b$var$FocusGroup = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
|
|
674
|
+
const { __scopeNavigationMenu: __scopeNavigationMenu , ...groupProps } = props;
|
|
675
|
+
const context = $322c88a641701f3b$var$useNavigationMenuContext($322c88a641701f3b$var$FOCUS_GROUP_NAME, __scopeNavigationMenu);
|
|
676
|
+
return /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$FocusGroupCollection.Provider, {
|
|
677
|
+
scope: __scopeNavigationMenu
|
|
678
|
+
}, /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$FocusGroupCollection.Slot, {
|
|
679
|
+
scope: __scopeNavigationMenu
|
|
680
|
+
}, /*#__PURE__*/ $yHMN2$createElement($yHMN2$Primitive.div, $yHMN2$babelruntimehelpersesmextends({
|
|
681
|
+
dir: context.dir
|
|
682
|
+
}, groupProps, {
|
|
683
|
+
ref: forwardedRef
|
|
684
|
+
}))));
|
|
685
|
+
});
|
|
686
|
+
/* -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$ARROW_KEYS = [
|
|
687
|
+
'ArrowRight',
|
|
688
|
+
'ArrowLeft',
|
|
689
|
+
'ArrowUp',
|
|
690
|
+
'ArrowDown'
|
|
691
|
+
];
|
|
692
|
+
const $322c88a641701f3b$var$FOCUS_GROUP_ITEM_NAME = 'FocusGroupItem';
|
|
693
|
+
const $322c88a641701f3b$var$FocusGroupItem = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
|
|
694
|
+
const { __scopeNavigationMenu: __scopeNavigationMenu , ...groupProps } = props;
|
|
695
|
+
const getItems = $322c88a641701f3b$var$useFocusGroupCollection(__scopeNavigationMenu);
|
|
696
|
+
const context = $322c88a641701f3b$var$useNavigationMenuContext($322c88a641701f3b$var$FOCUS_GROUP_ITEM_NAME, __scopeNavigationMenu);
|
|
697
|
+
return /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$FocusGroupCollection.ItemSlot, {
|
|
698
|
+
scope: __scopeNavigationMenu
|
|
699
|
+
}, /*#__PURE__*/ $yHMN2$createElement($yHMN2$Primitive.button, $yHMN2$babelruntimehelpersesmextends({}, groupProps, {
|
|
700
|
+
ref: forwardedRef,
|
|
701
|
+
onKeyDown: $yHMN2$composeEventHandlers(props.onKeyDown, (event)=>{
|
|
702
|
+
const isFocusNavigationKey = [
|
|
703
|
+
'Home',
|
|
704
|
+
'End',
|
|
705
|
+
...$322c88a641701f3b$var$ARROW_KEYS
|
|
706
|
+
].includes(event.key);
|
|
707
|
+
if (isFocusNavigationKey) {
|
|
708
|
+
let candidateNodes = getItems().map((item)=>item.ref.current
|
|
709
|
+
);
|
|
710
|
+
const prevItemKey = context.dir === 'rtl' ? 'ArrowRight' : 'ArrowLeft';
|
|
711
|
+
const prevKeys = [
|
|
712
|
+
prevItemKey,
|
|
713
|
+
'ArrowUp',
|
|
714
|
+
'End'
|
|
715
|
+
];
|
|
716
|
+
if (prevKeys.includes(event.key)) candidateNodes.reverse();
|
|
717
|
+
if ($322c88a641701f3b$var$ARROW_KEYS.includes(event.key)) {
|
|
718
|
+
const currentIndex = candidateNodes.indexOf(event.currentTarget);
|
|
719
|
+
candidateNodes = candidateNodes.slice(currentIndex + 1);
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Imperative focus during keydown is risky so we prevent React's batching updates
|
|
723
|
+
* to avoid potential bugs. See: https://github.com/facebook/react/issues/20332
|
|
724
|
+
*/ setTimeout(()=>$322c88a641701f3b$var$focusFirst(candidateNodes)
|
|
725
|
+
); // Prevent page scroll while navigating
|
|
726
|
+
event.preventDefault();
|
|
727
|
+
}
|
|
728
|
+
})
|
|
729
|
+
})));
|
|
730
|
+
});
|
|
731
|
+
/**
|
|
732
|
+
* Returns a list of potential tabbable candidates.
|
|
733
|
+
*
|
|
734
|
+
* NOTE: This is only a close approximation. For example it doesn't take into account cases like when
|
|
735
|
+
* elements are not visible. This cannot be worked out easily by just reading a property, but rather
|
|
736
|
+
* necessitate runtime knowledge (computed styles, etc). We deal with these cases separately.
|
|
737
|
+
*
|
|
738
|
+
* See: https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker
|
|
739
|
+
* Credit: https://github.com/discord/focus-layers/blob/master/src/util/wrapFocus.tsx#L1
|
|
740
|
+
*/ function $322c88a641701f3b$var$getTabbableCandidates(container) {
|
|
741
|
+
const nodes = [];
|
|
742
|
+
const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
|
|
743
|
+
acceptNode: (node)=>{
|
|
744
|
+
const isHiddenInput = node.tagName === 'INPUT' && node.type === 'hidden';
|
|
745
|
+
if (node.disabled || node.hidden || isHiddenInput) return NodeFilter.FILTER_SKIP; // `.tabIndex` is not the same as the `tabindex` attribute. It works on the
|
|
746
|
+
// runtime's understanding of tabbability, so this automatically accounts
|
|
747
|
+
// for any kind of element that could be tabbed to.
|
|
748
|
+
return node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
while(walker.nextNode())nodes.push(walker.currentNode); // we do not take into account the order of nodes with positive `tabIndex` as it
|
|
752
|
+
// hinders accessibility to have tab order different from visual order.
|
|
753
|
+
return nodes;
|
|
754
|
+
}
|
|
755
|
+
function $322c88a641701f3b$var$focusFirst(candidates) {
|
|
756
|
+
const previouslyFocusedElement = document.activeElement;
|
|
757
|
+
return candidates.some((candidate)=>{
|
|
758
|
+
// if focus is already where we want to go, we don't want to keep going through the candidates
|
|
759
|
+
if (candidate === previouslyFocusedElement) return true;
|
|
760
|
+
candidate.focus();
|
|
761
|
+
return document.activeElement !== previouslyFocusedElement;
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
function $322c88a641701f3b$var$removeFromTabOrder(candidates) {
|
|
765
|
+
candidates.forEach((candidate)=>{
|
|
766
|
+
candidate.dataset.tabindex = candidate.getAttribute('tabindex') || '';
|
|
767
|
+
candidate.setAttribute('tabindex', '-1');
|
|
768
|
+
});
|
|
769
|
+
return ()=>{
|
|
770
|
+
candidates.forEach((candidate)=>{
|
|
771
|
+
const prevTabIndex = candidate.dataset.tabindex;
|
|
772
|
+
candidate.setAttribute('tabindex', prevTabIndex);
|
|
773
|
+
});
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
function $322c88a641701f3b$var$useResizeObserver(element, onResize) {
|
|
777
|
+
const handleResize = $yHMN2$useCallbackRef(onResize);
|
|
778
|
+
$yHMN2$useLayoutEffect(()=>{
|
|
779
|
+
let rAF = 0;
|
|
780
|
+
if (element) {
|
|
781
|
+
/**
|
|
782
|
+
* Resize Observer will throw an often benign error that says `ResizeObserver loop
|
|
783
|
+
* completed with undelivered notifications`. This means that ResizeObserver was not
|
|
784
|
+
* able to deliver all observations within a single animation frame, so we use
|
|
785
|
+
* `requestAnimationFrame` to ensure we don't deliver unnecessary observations.
|
|
786
|
+
* Further reading: https://github.com/WICG/resize-observer/issues/38
|
|
787
|
+
*/ const resizeObserver = new ResizeObserver(()=>{
|
|
788
|
+
cancelAnimationFrame(rAF);
|
|
789
|
+
rAF = window.requestAnimationFrame(handleResize);
|
|
790
|
+
});
|
|
791
|
+
resizeObserver.observe(element);
|
|
792
|
+
return ()=>{
|
|
793
|
+
window.cancelAnimationFrame(rAF);
|
|
794
|
+
resizeObserver.unobserve(element);
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
}, [
|
|
798
|
+
element,
|
|
799
|
+
handleResize
|
|
800
|
+
]);
|
|
801
|
+
}
|
|
802
|
+
function $322c88a641701f3b$var$getOpenState(open) {
|
|
803
|
+
return open ? 'open' : 'closed';
|
|
804
|
+
}
|
|
805
|
+
function $322c88a641701f3b$var$makeTriggerId(baseId, value) {
|
|
806
|
+
return `${baseId}-trigger-${value}`;
|
|
807
|
+
}
|
|
808
|
+
function $322c88a641701f3b$var$makeContentId(baseId, value) {
|
|
809
|
+
return `${baseId}-content-${value}`;
|
|
810
|
+
}
|
|
811
|
+
function $322c88a641701f3b$var$whenMouse(handler) {
|
|
812
|
+
return (event)=>event.pointerType === 'mouse' ? handler(event) : undefined
|
|
813
|
+
;
|
|
814
|
+
}
|
|
815
|
+
/* -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$export$be92b6f5f03c0fe9 = $322c88a641701f3b$export$5b2278cf1e8bcae2;
|
|
816
|
+
const $322c88a641701f3b$export$d7a01e11500dfb6f = $322c88a641701f3b$export$5958edd6c4ee7c79;
|
|
817
|
+
const $322c88a641701f3b$export$54c2e3dc7acea9f5 = $322c88a641701f3b$export$c361068a95fd2286;
|
|
818
|
+
const $322c88a641701f3b$export$6d08773d2e66f8f2 = $322c88a641701f3b$export$ffdbb83a2de845c2;
|
|
819
|
+
const $322c88a641701f3b$export$41fb9f06171c75f4 = $322c88a641701f3b$export$37fe8002734d8f2;
|
|
820
|
+
const $322c88a641701f3b$export$a6c7ac8248d6e38a = $322c88a641701f3b$export$6893bf21536567da;
|
|
821
|
+
const $322c88a641701f3b$export$adb584737d712b70 = $322c88a641701f3b$export$8ddb526647c0d8fb;
|
|
822
|
+
const $322c88a641701f3b$export$7c6e2c02157bb7d2 = $322c88a641701f3b$export$38e00e996c2f93f7;
|
|
823
|
+
const $322c88a641701f3b$export$d5c6c08dc2d3ca7 = $322c88a641701f3b$export$ee880b97cc6d44a5;
|
|
824
|
+
|
|
825
|
+
|
|
826
|
+
|
|
827
|
+
|
|
828
|
+
export {$322c88a641701f3b$export$fb8ea5af8c9fcdf0 as createNavigationMenuScope, $322c88a641701f3b$export$5b2278cf1e8bcae2 as NavigationMenu, $322c88a641701f3b$export$5958edd6c4ee7c79 as NavigationMenuSub, $322c88a641701f3b$export$c361068a95fd2286 as NavigationMenuList, $322c88a641701f3b$export$ffdbb83a2de845c2 as NavigationMenuItem, $322c88a641701f3b$export$37fe8002734d8f2 as NavigationMenuTrigger, $322c88a641701f3b$export$6893bf21536567da as NavigationMenuLink, $322c88a641701f3b$export$8ddb526647c0d8fb as NavigationMenuIndicator, $322c88a641701f3b$export$38e00e996c2f93f7 as NavigationMenuContent, $322c88a641701f3b$export$ee880b97cc6d44a5 as NavigationMenuViewport, $322c88a641701f3b$export$be92b6f5f03c0fe9 as Root, $322c88a641701f3b$export$d7a01e11500dfb6f as Sub, $322c88a641701f3b$export$54c2e3dc7acea9f5 as List, $322c88a641701f3b$export$6d08773d2e66f8f2 as Item, $322c88a641701f3b$export$41fb9f06171c75f4 as Trigger, $322c88a641701f3b$export$a6c7ac8248d6e38a as Link, $322c88a641701f3b$export$adb584737d712b70 as Indicator, $322c88a641701f3b$export$7c6e2c02157bb7d2 as Content, $322c88a641701f3b$export$d5c6c08dc2d3ca7 as Viewport};
|
|
2
829
|
//# sourceMappingURL=index.module.js.map
|