@headlessui/react
Advanced tools
Comparing version 2.1.5 to 2.1.6
@@ -1,1 +0,1 @@ | ||
"use client";import{useFocusRing as Q}from"@react-aria/focus";import{useHover as Y}from"@react-aria/interactions";import y,{Fragment as G,createContext as I,useContext as x,useEffect as K,useMemo as C,useReducer as Z,useRef as W,useState as ee}from"react";import{useActivePress as te}from'../../hooks/use-active-press.js';import{useEvent as P}from'../../hooks/use-event.js';import{useId as j}from'../../hooks/use-id.js';import{useResolveButtonType as ne}from'../../hooks/use-resolve-button-type.js';import{optionalRef as oe,useSyncRefs as L}from'../../hooks/use-sync-refs.js';import{transitionDataAttributes as le,useTransition as se}from'../../hooks/use-transition.js';import{CloseProvider as re}from'../../internal/close-provider.js';import{OpenClosedProvider as ue,ResetOpenClosedProvider as ie,State as R,useOpenClosed as ae}from'../../internal/open-closed.js';import{isDisabledReactIssue7711 as pe}from'../../utils/bugs.js';import{match as B}from'../../utils/match.js';import{getOwnerDocument as ce}from'../../utils/owner.js';import{RenderFeatures as $,forwardRefWithAs as v,mergeProps as J,render as O,useMergeRefsFn as X}from'../../utils/render.js';import{startTransition as de}from'../../utils/start-transition.js';import{Keys as g}from'../keyboard.js';var Te=(l=>(l[l.Open=0]="Open",l[l.Closed=1]="Closed",l))(Te||{}),fe=(n=>(n[n.ToggleDisclosure=0]="ToggleDisclosure",n[n.CloseDisclosure=1]="CloseDisclosure",n[n.SetButtonId=2]="SetButtonId",n[n.SetPanelId=3]="SetPanelId",n[n.SetButtonElement=4]="SetButtonElement",n[n.SetPanelElement=5]="SetPanelElement",n))(fe||{});let me={[0]:e=>({...e,disclosureState:B(e.disclosureState,{[0]:1,[1]:0})}),[1]:e=>e.disclosureState===1?e:{...e,disclosureState:1},[2](e,t){return e.buttonId===t.buttonId?e:{...e,buttonId:t.buttonId}},[3](e,t){return e.panelId===t.panelId?e:{...e,panelId:t.panelId}},[4](e,t){return e.buttonElement===t.element?e:{...e,buttonElement:t.element}},[5](e,t){return e.panelElement===t.element?e:{...e,panelElement:t.element}}},_=I(null);_.displayName="DisclosureContext";function M(e){let t=x(_);if(t===null){let l=new Error(`<${e} /> is missing a parent <Disclosure /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(l,M),l}return t}let F=I(null);F.displayName="DisclosureAPIContext";function V(e){let t=x(F);if(t===null){let l=new Error(`<${e} /> is missing a parent <Disclosure /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(l,V),l}return t}let H=I(null);H.displayName="DisclosurePanelContext";function De(){return x(H)}function ye(e,t){return B(t.type,me,e,t)}let Pe=G;function Ee(e,t){let{defaultOpen:l=!1,...p}=e,i=W(null),c=L(t,oe(a=>{i.current=a},e.as===void 0||e.as===G)),n=Z(ye,{disclosureState:l?0:1,buttonElement:null,panelElement:null,buttonId:null,panelId:null}),[{disclosureState:o,buttonId:s},f]=n,r=P(a=>{f({type:1});let T=ce(i);if(!T||!s)return;let d=(()=>a?a instanceof HTMLElement?a:a.current instanceof HTMLElement?a.current:T.getElementById(s):T.getElementById(s))();d==null||d.focus()}),E=C(()=>({close:r}),[r]),m=C(()=>({open:o===0,close:r}),[o,r]),D={ref:c};return y.createElement(_.Provider,{value:n},y.createElement(F.Provider,{value:E},y.createElement(re,{value:r},y.createElement(ue,{value:B(o,{[0]:R.Open,[1]:R.Closed})},O({ourProps:D,theirProps:p,slot:m,defaultTag:Pe,name:"Disclosure"})))))}let Se="button";function ge(e,t){let l=j(),{id:p=`headlessui-disclosure-button-${l}`,disabled:i=!1,autoFocus:c=!1,...n}=e,[o,s]=M("Disclosure.Button"),f=De(),r=f===null?!1:f===o.panelId,E=W(null),m=L(E,t,r?null:P(u=>s({type:4,element:u}))),D=X();K(()=>{if(!r)return s({type:2,buttonId:p}),()=>{s({type:2,buttonId:null})}},[p,s,r]);let a=P(u=>{var S;if(r){if(o.disclosureState===1)return;switch(u.key){case g.Space:case g.Enter:u.preventDefault(),u.stopPropagation(),s({type:0}),(S=o.buttonElement)==null||S.focus();break}}else switch(u.key){case g.Space:case g.Enter:u.preventDefault(),u.stopPropagation(),s({type:0});break}}),T=P(u=>{switch(u.key){case g.Space:u.preventDefault();break}}),d=P(u=>{var S;pe(u.currentTarget)||i||(r?(s({type:0}),(S=o.buttonElement)==null||S.focus()):s({type:0}))}),{isFocusVisible:A,focusProps:b}=Q({autoFocus:c}),{isHovered:h,hoverProps:U}=Y({isDisabled:i}),{pressed:N,pressProps:k}=te({disabled:i}),q=C(()=>({open:o.disclosureState===0,hover:h,active:N,disabled:i,focus:A,autofocus:c}),[o,h,N,A,i,c]),w=ne(e,o.buttonElement),z=r?J({ref:m,type:w,disabled:i||void 0,autoFocus:c,onKeyDown:a,onClick:d},b,U,k):J({ref:m,id:p,type:w,"aria-expanded":o.disclosureState===0,"aria-controls":o.panelElement?o.panelId:void 0,disabled:i||void 0,autoFocus:c,onKeyDown:a,onKeyUp:T,onClick:d},b,U,k);return O({mergeRefs:D,ourProps:z,theirProps:n,slot:q,defaultTag:Se,name:"Disclosure.Button"})}let Ae="div",be=$.RenderStrategy|$.Static;function Ce(e,t){let l=j(),{id:p=`headlessui-disclosure-panel-${l}`,transition:i=!1,...c}=e,[n,o]=M("Disclosure.Panel"),{close:s}=V("Disclosure.Panel"),f=X(),[r,E]=ee(null),m=L(t,P(b=>{de(()=>o({type:5,element:b}))}),E);K(()=>(o({type:3,panelId:p}),()=>{o({type:3,panelId:null})}),[p,o]);let D=ae(),[a,T]=se(i,r,D!==null?(D&R.Open)===R.Open:n.disclosureState===0),d=C(()=>({open:n.disclosureState===0,close:s}),[n.disclosureState,s]),A={ref:m,id:p,...le(T)};return y.createElement(ie,null,y.createElement(H.Provider,{value:n.panelId},O({mergeRefs:f,ourProps:A,theirProps:c,slot:d,defaultTag:Ae,features:be,visible:a,name:"Disclosure.Panel"})))}let Re=v(Ee),Ie=v(ge),xe=v(Ce),$e=Object.assign(Re,{Button:Ie,Panel:xe});export{$e as Disclosure,Ie as DisclosureButton,xe as DisclosurePanel}; | ||
"use client";import{useFocusRing as Q}from"@react-aria/focus";import{useHover as Y}from"@react-aria/interactions";import y,{Fragment as G,createContext as I,useContext as x,useEffect as K,useMemo as C,useReducer as Z,useRef as W,useState as ee}from"react";import{useActivePress as te}from'../../hooks/use-active-press.js';import{useEvent as P}from'../../hooks/use-event.js';import{useId as j}from'../../hooks/use-id.js';import{useResolveButtonType as ne}from'../../hooks/use-resolve-button-type.js';import{optionalRef as oe,useSyncRefs as L}from'../../hooks/use-sync-refs.js';import{transitionDataAttributes as le,useTransition as re}from'../../hooks/use-transition.js';import{CloseProvider as se}from'../../internal/close-provider.js';import{OpenClosedProvider as ue,ResetOpenClosedProvider as ie,State as R,useOpenClosed as ae}from'../../internal/open-closed.js';import{isDisabledReactIssue7711 as pe}from'../../utils/bugs.js';import{match as B}from'../../utils/match.js';import{getOwnerDocument as ce}from'../../utils/owner.js';import{RenderFeatures as $,forwardRefWithAs as v,mergeProps as J,render as O,useMergeRefsFn as X}from'../../utils/render.js';import{startTransition as de}from'../../utils/start-transition.js';import{Keys as g}from'../keyboard.js';var Te=(l=>(l[l.Open=0]="Open",l[l.Closed=1]="Closed",l))(Te||{}),fe=(n=>(n[n.ToggleDisclosure=0]="ToggleDisclosure",n[n.CloseDisclosure=1]="CloseDisclosure",n[n.SetButtonId=2]="SetButtonId",n[n.SetPanelId=3]="SetPanelId",n[n.SetButtonElement=4]="SetButtonElement",n[n.SetPanelElement=5]="SetPanelElement",n))(fe||{});let me={[0]:e=>({...e,disclosureState:B(e.disclosureState,{[0]:1,[1]:0})}),[1]:e=>e.disclosureState===1?e:{...e,disclosureState:1},[2](e,t){return e.buttonId===t.buttonId?e:{...e,buttonId:t.buttonId}},[3](e,t){return e.panelId===t.panelId?e:{...e,panelId:t.panelId}},[4](e,t){return e.buttonElement===t.element?e:{...e,buttonElement:t.element}},[5](e,t){return e.panelElement===t.element?e:{...e,panelElement:t.element}}},_=I(null);_.displayName="DisclosureContext";function M(e){let t=x(_);if(t===null){let l=new Error(`<${e} /> is missing a parent <Disclosure /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(l,M),l}return t}let F=I(null);F.displayName="DisclosureAPIContext";function V(e){let t=x(F);if(t===null){let l=new Error(`<${e} /> is missing a parent <Disclosure /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(l,V),l}return t}let H=I(null);H.displayName="DisclosurePanelContext";function De(){return x(H)}function ye(e,t){return B(t.type,me,e,t)}let Pe=G;function Ee(e,t){let{defaultOpen:l=!1,...p}=e,i=W(null),c=L(t,oe(a=>{i.current=a},e.as===void 0||e.as===G)),n=Z(ye,{disclosureState:l?0:1,buttonElement:null,panelElement:null,buttonId:null,panelId:null}),[{disclosureState:o,buttonId:r},f]=n,s=P(a=>{f({type:1});let T=ce(i);if(!T||!r)return;let d=(()=>a?a instanceof HTMLElement?a:a.current instanceof HTMLElement?a.current:T.getElementById(r):T.getElementById(r))();d==null||d.focus()}),E=C(()=>({close:s}),[s]),m=C(()=>({open:o===0,close:s}),[o,s]),D={ref:c};return y.createElement(_.Provider,{value:n},y.createElement(F.Provider,{value:E},y.createElement(se,{value:s},y.createElement(ue,{value:B(o,{[0]:R.Open,[1]:R.Closed})},O({ourProps:D,theirProps:p,slot:m,defaultTag:Pe,name:"Disclosure"})))))}let Se="button";function ge(e,t){let l=j(),{id:p=`headlessui-disclosure-button-${l}`,disabled:i=!1,autoFocus:c=!1,...n}=e,[o,r]=M("Disclosure.Button"),f=De(),s=f===null?!1:f===o.panelId,E=W(null),m=L(E,t,P(u=>{if(!s)return r({type:4,element:u})})),D=X();K(()=>{if(!s)return r({type:2,buttonId:p}),()=>{r({type:2,buttonId:null})}},[p,r,s]);let a=P(u=>{var S;if(s){if(o.disclosureState===1)return;switch(u.key){case g.Space:case g.Enter:u.preventDefault(),u.stopPropagation(),r({type:0}),(S=o.buttonElement)==null||S.focus();break}}else switch(u.key){case g.Space:case g.Enter:u.preventDefault(),u.stopPropagation(),r({type:0});break}}),T=P(u=>{switch(u.key){case g.Space:u.preventDefault();break}}),d=P(u=>{var S;pe(u.currentTarget)||i||(s?(r({type:0}),(S=o.buttonElement)==null||S.focus()):r({type:0}))}),{isFocusVisible:A,focusProps:b}=Q({autoFocus:c}),{isHovered:h,hoverProps:U}=Y({isDisabled:i}),{pressed:N,pressProps:k}=te({disabled:i}),q=C(()=>({open:o.disclosureState===0,hover:h,active:N,disabled:i,focus:A,autofocus:c}),[o,h,N,A,i,c]),w=ne(e,o.buttonElement),z=s?J({ref:m,type:w,disabled:i||void 0,autoFocus:c,onKeyDown:a,onClick:d},b,U,k):J({ref:m,id:p,type:w,"aria-expanded":o.disclosureState===0,"aria-controls":o.panelElement?o.panelId:void 0,disabled:i||void 0,autoFocus:c,onKeyDown:a,onKeyUp:T,onClick:d},b,U,k);return O({mergeRefs:D,ourProps:z,theirProps:n,slot:q,defaultTag:Se,name:"Disclosure.Button"})}let Ae="div",be=$.RenderStrategy|$.Static;function Ce(e,t){let l=j(),{id:p=`headlessui-disclosure-panel-${l}`,transition:i=!1,...c}=e,[n,o]=M("Disclosure.Panel"),{close:r}=V("Disclosure.Panel"),f=X(),[s,E]=ee(null),m=L(t,P(b=>{de(()=>o({type:5,element:b}))}),E);K(()=>(o({type:3,panelId:p}),()=>{o({type:3,panelId:null})}),[p,o]);let D=ae(),[a,T]=re(i,s,D!==null?(D&R.Open)===R.Open:n.disclosureState===0),d=C(()=>({open:n.disclosureState===0,close:r}),[n.disclosureState,r]),A={ref:m,id:p,...le(T)};return y.createElement(ie,null,y.createElement(H.Provider,{value:n.panelId},O({mergeRefs:f,ourProps:A,theirProps:c,slot:d,defaultTag:Ae,features:be,visible:a,name:"Disclosure.Panel"})))}let Re=v(Ee),Ie=v(ge),xe=v(Ce),$e=Object.assign(Re,{Button:Ie,Panel:xe});export{$e as Disclosure,Ie as DisclosureButton,xe as DisclosurePanel}; |
@@ -1,1 +0,1 @@ | ||
"use client";import{useFocusRing as Ae}from"@react-aria/focus";import{useHover as Re}from"@react-aria/interactions";import h,{Fragment as Te,createContext as le,createRef as he,useCallback as me,useContext as ae,useEffect as De,useMemo as k,useReducer as _e,useRef as se,useState as Ie}from"react";import{flushSync as U}from"react-dom";import{useActivePress as Ce}from'../../hooks/use-active-press.js';import{useByComparator as Fe}from'../../hooks/use-by-comparator.js';import{useControllable as Me}from'../../hooks/use-controllable.js';import{useDefaultValue as Be}from'../../hooks/use-default-value.js';import{useDidElementMove as we}from'../../hooks/use-did-element-move.js';import{useDisposables as xe}from'../../hooks/use-disposables.js';import{useElementSize as ke}from'../../hooks/use-element-size.js';import{useEvent as T}from'../../hooks/use-event.js';import{useId as pe}from'../../hooks/use-id.js';import{useInertOthers as Ue}from'../../hooks/use-inert-others.js';import{useIsoMorphicEffect as ue}from'../../hooks/use-iso-morphic-effect.js';import{useLatestValue as Ne}from'../../hooks/use-latest-value.js';import{useOnDisappear as He}from'../../hooks/use-on-disappear.js';import{useOutsideClick as Ge}from'../../hooks/use-outside-click.js';import{useOwnerDocument as Ve}from'../../hooks/use-owner.js';import{useResolveButtonType as Ke}from'../../hooks/use-resolve-button-type.js';import{useScrollLock as je}from'../../hooks/use-scroll-lock.js';import{useSyncRefs as K}from'../../hooks/use-sync-refs.js';import{useTextValue as ze}from'../../hooks/use-text-value.js';import{useTrackedPointer as We}from'../../hooks/use-tracked-pointer.js';import{transitionDataAttributes as Qe,useTransition as Xe}from'../../hooks/use-transition.js';import{useDisabled as Je}from'../../internal/disabled.js';import{FloatingProvider as $e,useFloatingPanel as qe,useFloatingPanelProps as Ye,useFloatingReference as Ze,useFloatingReferenceProps as et,useResolvedAnchor as tt}from'../../internal/floating.js';import{FormFields as ot}from'../../internal/form-fields.js';import{useFrozenData as nt}from'../../internal/frozen.js';import{useProvidedId as it}from'../../internal/id.js';import{OpenClosedProvider as rt,State as q,useOpenClosed as lt}from'../../internal/open-closed.js';import{isDisabledReactIssue7711 as at}from'../../utils/bugs.js';import{Focus as v,calculateActiveIndex as de}from'../../utils/calculate-active-index.js';import{disposables as st}from'../../utils/disposables.js';import{Focus as Oe,FocusableMode as pt,focusFrom as ut,isFocusableElement as dt,sortByDomNode as ct}from'../../utils/focus-management.js';import{attemptSubmit as ft}from'../../utils/form.js';import{match as G}from'../../utils/match.js';import{getOwnerDocument as bt}from'../../utils/owner.js';import{RenderFeatures as ye,forwardRefWithAs as j,mergeProps as ve,render as z}from'../../utils/render.js';import{useDescribedBy as Tt}from'../description/description.js';import{Keys as E}from'../keyboard.js';import{Label as mt,useLabelledBy as xt,useLabels as Ot}from'../label/label.js';import{Portal as yt}from'../portal/portal.js';var vt=(o=>(o[o.Open=0]="Open",o[o.Closed=1]="Closed",o))(vt||{}),gt=(o=>(o[o.Single=0]="Single",o[o.Multi=1]="Multi",o))(gt||{}),Lt=(o=>(o[o.Pointer=0]="Pointer",o[o.Other=1]="Other",o))(Lt||{}),St=(n=>(n[n.OpenListbox=0]="OpenListbox",n[n.CloseListbox=1]="CloseListbox",n[n.GoToOption=2]="GoToOption",n[n.Search=3]="Search",n[n.ClearSearch=4]="ClearSearch",n[n.RegisterOption=5]="RegisterOption",n[n.UnregisterOption=6]="UnregisterOption",n[n.SetButtonElement=7]="SetButtonElement",n[n.SetOptionsElement=8]="SetOptionsElement",n))(St||{});function ce(e,i=o=>o){let o=e.activeOptionIndex!==null?e.options[e.activeOptionIndex]:null,r=ct(i(e.options.slice()),m=>m.dataRef.current.domRef.current),a=o?r.indexOf(o):null;return a===-1&&(a=null),{options:r,activeOptionIndex:a}}let Et={[1](e){return e.dataRef.current.disabled||e.listboxState===1?e:{...e,activeOptionIndex:null,listboxState:1,__demoMode:!1}},[0](e){if(e.dataRef.current.disabled||e.listboxState===0)return e;let i=e.activeOptionIndex,{isSelected:o}=e.dataRef.current,r=e.options.findIndex(a=>o(a.dataRef.current.value));return r!==-1&&(i=r),{...e,listboxState:0,activeOptionIndex:i,__demoMode:!1}},[2](e,i){var m,x,d,p,n;if(e.dataRef.current.disabled||e.listboxState===1)return e;let o={...e,searchQuery:"",activationTrigger:(m=i.trigger)!=null?m:1,__demoMode:!1};if(i.focus===v.Nothing)return{...o,activeOptionIndex:null};if(i.focus===v.Specific)return{...o,activeOptionIndex:e.options.findIndex(u=>u.id===i.id)};if(i.focus===v.Previous){let u=e.activeOptionIndex;if(u!==null){let P=e.options[u].dataRef.current.domRef,t=de(i,{resolveItems:()=>e.options,resolveActiveIndex:()=>e.activeOptionIndex,resolveId:s=>s.id,resolveDisabled:s=>s.dataRef.current.disabled});if(t!==null){let s=e.options[t].dataRef.current.domRef;if(((x=P.current)==null?void 0:x.previousElementSibling)===s.current||((d=s.current)==null?void 0:d.previousElementSibling)===null)return{...o,activeOptionIndex:t}}}}else if(i.focus===v.Next){let u=e.activeOptionIndex;if(u!==null){let P=e.options[u].dataRef.current.domRef,t=de(i,{resolveItems:()=>e.options,resolveActiveIndex:()=>e.activeOptionIndex,resolveId:s=>s.id,resolveDisabled:s=>s.dataRef.current.disabled});if(t!==null){let s=e.options[t].dataRef.current.domRef;if(((p=P.current)==null?void 0:p.nextElementSibling)===s.current||((n=s.current)==null?void 0:n.nextElementSibling)===null)return{...o,activeOptionIndex:t}}}}let r=ce(e),a=de(i,{resolveItems:()=>r.options,resolveActiveIndex:()=>r.activeOptionIndex,resolveId:u=>u.id,resolveDisabled:u=>u.dataRef.current.disabled});return{...o,...r,activeOptionIndex:a}},[3]:(e,i)=>{if(e.dataRef.current.disabled||e.listboxState===1)return e;let r=e.searchQuery!==""?0:1,a=e.searchQuery+i.value.toLowerCase(),x=(e.activeOptionIndex!==null?e.options.slice(e.activeOptionIndex+r).concat(e.options.slice(0,e.activeOptionIndex+r)):e.options).find(p=>{var n;return!p.dataRef.current.disabled&&((n=p.dataRef.current.textValue)==null?void 0:n.startsWith(a))}),d=x?e.options.indexOf(x):-1;return d===-1||d===e.activeOptionIndex?{...e,searchQuery:a}:{...e,searchQuery:a,activeOptionIndex:d,activationTrigger:1}},[4](e){return e.dataRef.current.disabled||e.listboxState===1||e.searchQuery===""?e:{...e,searchQuery:""}},[5]:(e,i)=>{let o={id:i.id,dataRef:i.dataRef},r=ce(e,a=>[...a,o]);return e.activeOptionIndex===null&&e.dataRef.current.isSelected(i.dataRef.current.value)&&(r.activeOptionIndex=r.options.indexOf(o)),{...e,...r}},[6]:(e,i)=>{let o=ce(e,r=>{let a=r.findIndex(m=>m.id===i.id);return a!==-1&&r.splice(a,1),r});return{...e,...o,activationTrigger:1}},[7]:(e,i)=>e.buttonElement===i.element?e:{...e,buttonElement:i.element},[8]:(e,i)=>e.optionsElement===i.element?e:{...e,optionsElement:i.element}},fe=le(null);fe.displayName="ListboxActionsContext";function Y(e){let i=ae(fe);if(i===null){let o=new Error(`<${e} /> is missing a parent <Listbox /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(o,Y),o}return i}let Z=le(null);Z.displayName="ListboxDataContext";function W(e){let i=ae(Z);if(i===null){let o=new Error(`<${e} /> is missing a parent <Listbox /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(o,W),o}return i}function Pt(e,i){return G(i.type,Et,e,i)}let At=Te;function Rt(e,i){var be;let o=Je(),{value:r,defaultValue:a,form:m,name:x,onChange:d,by:p,invalid:n=!1,disabled:u=o||!1,horizontal:P=!1,multiple:t=!1,__demoMode:s=!1,...F}=e;const M=P?"horizontal":"vertical";let D=K(i),_=Be(a),[O=t?[]:void 0,g]=Me(r,d,_),[R,y]=_e(Pt,{dataRef:he(),listboxState:s?0:1,options:[],searchQuery:"",activeOptionIndex:null,activationTrigger:1,optionsVisible:!1,buttonElement:null,optionsElement:null,__demoMode:s}),B=se({static:!1,hold:!1}),w=se(new Map),f=Fe(p),A=me(b=>G(c.mode,{[1]:()=>O.some(S=>f(S,b)),[0]:()=>f(O,b)}),[O]),c=k(()=>({...R,value:O,disabled:u,invalid:n,mode:t?1:0,orientation:M,compare:f,isSelected:A,optionsPropsRef:B,listRef:w}),[O,u,n,t,R,w]);ue(()=>{R.dataRef.current=c},[c]);let L=c.listboxState===0;Ge(L,[c.buttonElement,c.optionsElement],(b,S)=>{var C;y({type:1}),dt(S,pt.Loose)||(b.preventDefault(),(C=c.buttonElement)==null||C.focus())});let N=k(()=>({open:c.listboxState===0,disabled:u,invalid:n,value:O}),[c,u,O,n]),ee=T(b=>{let S=c.options.find(C=>C.id===b);S&&V(S.dataRef.current.value)}),te=T(()=>{if(c.activeOptionIndex!==null){let{dataRef:b,id:S}=c.options[c.activeOptionIndex];V(b.current.value),y({type:2,focus:v.Specific,id:S})}}),oe=T(()=>y({type:0})),Q=T(()=>y({type:1})),X=xe(),ne=T((b,S,C)=>{X.dispose(),X.microTask(()=>b===v.Specific?y({type:2,focus:v.Specific,id:S,trigger:C}):y({type:2,focus:b,trigger:C}))}),ie=T((b,S)=>(y({type:5,id:b,dataRef:S}),()=>y({type:6,id:b}))),V=T(b=>G(c.mode,{[0](){return g==null?void 0:g(b)},[1](){let S=c.value.slice(),C=S.findIndex(Pe=>f(Pe,b));return C===-1?S.push(b):S.splice(C,1),g==null?void 0:g(S)}})),J=T(b=>y({type:3,value:b})),$=T(()=>y({type:4})),l=T(b=>{y({type:7,element:b})}),I=T(b=>{y({type:8,element:b})}),H=k(()=>({onChange:V,registerOption:ie,goToOption:ne,closeListbox:Q,openListbox:oe,selectActiveOption:te,selectOption:ee,search:J,clearSearch:$,setButtonElement:l,setOptionsElement:I}),[]),[re,Le]=Ot({inherit:!0}),Se={ref:D},Ee=me(()=>{if(_!==void 0)return g==null?void 0:g(_)},[g,_]);return h.createElement(Le,{value:re,props:{htmlFor:(be=c.buttonElement)==null?void 0:be.id},slot:{open:c.listboxState===0,disabled:u}},h.createElement($e,null,h.createElement(fe.Provider,{value:H},h.createElement(Z.Provider,{value:c},h.createElement(rt,{value:G(c.listboxState,{[0]:q.Open,[1]:q.Closed})},x!=null&&O!=null&&h.createElement(ot,{disabled:u,data:{[x]:O},form:m,onReset:Ee}),z({ourProps:Se,theirProps:F,slot:N,defaultTag:At,name:"Listbox"}))))))}let ht="button";function Dt(e,i){var c;let o=W("Listbox.Button"),r=Y("Listbox.Button"),a=pe(),m=it(),{id:x=m||`headlessui-listbox-button-${a}`,disabled:d=o.disabled||!1,autoFocus:p=!1,...n}=e,u=K(i,Ze(),r.setButtonElement),P=et(),t=T(L=>{switch(L.key){case E.Enter:ft(L.currentTarget);break;case E.Space:case E.ArrowDown:L.preventDefault(),U(()=>r.openListbox()),o.value||r.goToOption(v.First);break;case E.ArrowUp:L.preventDefault(),U(()=>r.openListbox()),o.value||r.goToOption(v.Last);break}}),s=T(L=>{switch(L.key){case E.Space:L.preventDefault();break}}),F=T(L=>{var N;if(at(L.currentTarget))return L.preventDefault();o.listboxState===0?(U(()=>r.closeListbox()),(N=o.buttonElement)==null||N.focus({preventScroll:!0})):(L.preventDefault(),r.openListbox())}),M=T(L=>L.preventDefault()),D=xt([x]),_=Tt(),{isFocusVisible:O,focusProps:g}=Ae({autoFocus:p}),{isHovered:R,hoverProps:y}=Re({isDisabled:d}),{pressed:B,pressProps:w}=Ce({disabled:d}),f=k(()=>({open:o.listboxState===0,active:B||o.listboxState===0,disabled:d,invalid:o.invalid,value:o.value,hover:R,focus:O,autofocus:p}),[o.listboxState,o.value,d,R,O,B,o.invalid,p]),A=ve(P(),{ref:u,id:x,type:Ke(e,o.buttonElement),"aria-haspopup":"listbox","aria-controls":(c=o.optionsElement)==null?void 0:c.id,"aria-expanded":o.listboxState===0,"aria-labelledby":D,"aria-describedby":_,disabled:d||void 0,autoFocus:p,onKeyDown:t,onKeyUp:s,onKeyPress:M,onClick:F},g,y,w);return z({ourProps:A,theirProps:n,slot:f,defaultTag:ht,name:"Listbox.Button"})}let ge=le(!1),_t="div",It=ye.RenderStrategy|ye.Static;function Ct(e,i){var J,$;let o=pe(),{id:r=`headlessui-listbox-options-${o}`,anchor:a,portal:m=!1,modal:x=!0,transition:d=!1,...p}=e,n=tt(a),[u,P]=Ie(null);n&&(m=!0);let t=W("Listbox.Options"),s=Y("Listbox.Options"),F=Ve(t.optionsElement),M=lt(),[D,_]=Xe(d,u,M!==null?(M&q.Open)===q.Open:t.listboxState===0);He(D,t.buttonElement,s.closeListbox);let O=t.__demoMode?!1:x&&t.listboxState===0;je(O,F);let g=t.__demoMode?!1:x&&t.listboxState===0;Ue(g,{allowed:T(()=>[t.buttonElement,t.optionsElement])});let R=t.listboxState!==0,B=we(R,t.buttonElement)?!1:D,w=D&&t.listboxState===1,f=nt(w,t.value),A=T(l=>t.compare(f,l)),c=k(()=>{var I;if(n==null||!((I=n==null?void 0:n.to)!=null&&I.includes("selection")))return null;let l=t.options.findIndex(H=>A(H.dataRef.current.value));return l===-1&&(l=0),l},[n,t.options]),L=(()=>{if(n==null)return;if(c===null)return{...n,inner:void 0};let l=Array.from(t.listRef.current.values());return{...n,inner:{listRef:{current:l},index:c}}})(),[N,ee]=qe(L),te=Ye(),oe=K(i,n?N:null,s.setOptionsElement,P),Q=xe();De(()=>{var I;let l=t.optionsElement;l&&t.listboxState===0&&l!==((I=bt(l))==null?void 0:I.activeElement)&&(l==null||l.focus({preventScroll:!0}))},[t.listboxState,t.optionsElement]);let X=T(l=>{var I,H;switch(Q.dispose(),l.key){case E.Space:if(t.searchQuery!=="")return l.preventDefault(),l.stopPropagation(),s.search(l.key);case E.Enter:if(l.preventDefault(),l.stopPropagation(),t.activeOptionIndex!==null){let{dataRef:re}=t.options[t.activeOptionIndex];s.onChange(re.current.value)}t.mode===0&&(U(()=>s.closeListbox()),(I=t.buttonElement)==null||I.focus({preventScroll:!0}));break;case G(t.orientation,{vertical:E.ArrowDown,horizontal:E.ArrowRight}):return l.preventDefault(),l.stopPropagation(),s.goToOption(v.Next);case G(t.orientation,{vertical:E.ArrowUp,horizontal:E.ArrowLeft}):return l.preventDefault(),l.stopPropagation(),s.goToOption(v.Previous);case E.Home:case E.PageUp:return l.preventDefault(),l.stopPropagation(),s.goToOption(v.First);case E.End:case E.PageDown:return l.preventDefault(),l.stopPropagation(),s.goToOption(v.Last);case E.Escape:l.preventDefault(),l.stopPropagation(),U(()=>s.closeListbox()),(H=t.buttonElement)==null||H.focus({preventScroll:!0});return;case E.Tab:l.preventDefault(),l.stopPropagation(),U(()=>s.closeListbox()),ut(t.buttonElement,l.shiftKey?Oe.Previous:Oe.Next);break;default:l.key.length===1&&(s.search(l.key),Q.setTimeout(()=>s.clearSearch(),350));break}}),ne=(J=t.buttonElement)==null?void 0:J.id,ie=k(()=>({open:t.listboxState===0}),[t.listboxState]),V=ve(n?te():{},{id:r,ref:oe,"aria-activedescendant":t.activeOptionIndex===null||($=t.options[t.activeOptionIndex])==null?void 0:$.id,"aria-multiselectable":t.mode===1?!0:void 0,"aria-labelledby":ne,"aria-orientation":t.orientation,onKeyDown:X,role:"listbox",tabIndex:t.listboxState===0?0:void 0,style:{...p.style,...ee,"--button-width":ke(t.buttonElement,!0).width},...Qe(_)});return h.createElement(yt,{enabled:m?e.static||D:!1},h.createElement(Z.Provider,{value:t.mode===1?t:{...t,isSelected:A}},z({ourProps:V,theirProps:p,slot:ie,defaultTag:_t,features:It,visible:B,name:"Listbox.Options"})))}let Ft="div";function Mt(e,i){let o=pe(),{id:r=`headlessui-listbox-option-${o}`,disabled:a=!1,value:m,...x}=e,d=ae(ge)===!0,p=W("Listbox.Option"),n=Y("Listbox.Option"),u=p.activeOptionIndex!==null?p.options[p.activeOptionIndex].id===r:!1,P=p.isSelected(m),t=se(null),s=ze(t),F=Ne({disabled:a,value:m,domRef:t,get textValue(){return s()}}),M=K(i,t,f=>{f?p.listRef.current.set(r,f):p.listRef.current.delete(r)});ue(()=>{if(!p.__demoMode&&p.listboxState===0&&u&&p.activationTrigger!==0)return st().requestAnimationFrame(()=>{var f,A;(A=(f=t.current)==null?void 0:f.scrollIntoView)==null||A.call(f,{block:"nearest"})})},[t,u,p.__demoMode,p.listboxState,p.activationTrigger,p.activeOptionIndex]),ue(()=>{if(!d)return n.registerOption(r,F)},[F,r,d]);let D=T(f=>{var A;if(a)return f.preventDefault();n.onChange(m),p.mode===0&&(U(()=>n.closeListbox()),(A=p.buttonElement)==null||A.focus({preventScroll:!0}))}),_=T(()=>{if(a)return n.goToOption(v.Nothing);n.goToOption(v.Specific,r)}),O=We(),g=T(f=>{O.update(f),!a&&(u||n.goToOption(v.Specific,r,0))}),R=T(f=>{O.wasMoved(f)&&(a||u||n.goToOption(v.Specific,r,0))}),y=T(f=>{O.wasMoved(f)&&(a||u&&n.goToOption(v.Nothing))}),B=k(()=>({active:u,focus:u,selected:P,disabled:a,selectedOption:P&&d}),[u,P,a,d]),w=d?{}:{id:r,ref:M,role:"option",tabIndex:a===!0?void 0:-1,"aria-disabled":a===!0?!0:void 0,"aria-selected":P,disabled:void 0,onClick:D,onFocus:_,onPointerEnter:g,onMouseEnter:g,onPointerMove:R,onMouseMove:R,onPointerLeave:y,onMouseLeave:y};return!P&&d?null:z({ourProps:w,theirProps:x,slot:B,defaultTag:Ft,name:"Listbox.Option"})}let Bt=Te;function wt(e,i){let{options:o,placeholder:r,...a}=e,x={ref:K(i)},d=W("ListboxSelectedOption"),p=k(()=>({}),[]),n=d.value===void 0||d.value===null||d.mode===1&&Array.isArray(d.value)&&d.value.length===0;return h.createElement(ge.Provider,{value:!0},z({ourProps:x,theirProps:{...a,children:h.createElement(h.Fragment,null,r&&n?r:o)},slot:p,defaultTag:Bt,name:"ListboxSelectedOption"}))}let kt=j(Rt),Ut=j(Dt),Nt=mt,Ht=j(Ct),Gt=j(Mt),Vt=j(wt),Fo=Object.assign(kt,{Button:Ut,Label:Nt,Options:Ht,Option:Gt,SelectedOption:Vt});export{Fo as Listbox,Ut as ListboxButton,Nt as ListboxLabel,Gt as ListboxOption,Ht as ListboxOptions,Vt as ListboxSelectedOption}; | ||
"use client";import{useFocusRing as Ae}from"@react-aria/focus";import{useHover as Re}from"@react-aria/interactions";import h,{Fragment as me,createContext as le,createRef as he,useCallback as ae,useContext as se,useEffect as De,useMemo as k,useReducer as _e,useRef as pe,useState as Ie}from"react";import{flushSync as U}from"react-dom";import{useActivePress as Ce}from'../../hooks/use-active-press.js';import{useByComparator as Fe}from'../../hooks/use-by-comparator.js';import{useControllable as Me}from'../../hooks/use-controllable.js';import{useDefaultValue as Be}from'../../hooks/use-default-value.js';import{useDidElementMove as we}from'../../hooks/use-did-element-move.js';import{useDisposables as xe}from'../../hooks/use-disposables.js';import{useElementSize as ke}from'../../hooks/use-element-size.js';import{useEvent as T}from'../../hooks/use-event.js';import{useId as ue}from'../../hooks/use-id.js';import{useInertOthers as Ue}from'../../hooks/use-inert-others.js';import{useIsoMorphicEffect as de}from'../../hooks/use-iso-morphic-effect.js';import{useLatestValue as Ne}from'../../hooks/use-latest-value.js';import{useOnDisappear as He}from'../../hooks/use-on-disappear.js';import{useOutsideClick as Ge}from'../../hooks/use-outside-click.js';import{useOwnerDocument as Ve}from'../../hooks/use-owner.js';import{useResolveButtonType as Ke}from'../../hooks/use-resolve-button-type.js';import{useScrollLock as je}from'../../hooks/use-scroll-lock.js';import{useSyncRefs as K}from'../../hooks/use-sync-refs.js';import{useTextValue as ze}from'../../hooks/use-text-value.js';import{useTrackedPointer as We}from'../../hooks/use-tracked-pointer.js';import{transitionDataAttributes as Qe,useTransition as Xe}from'../../hooks/use-transition.js';import{useDisabled as Je}from'../../internal/disabled.js';import{FloatingProvider as $e,useFloatingPanel as qe,useFloatingPanelProps as Ye,useFloatingReference as Ze,useFloatingReferenceProps as et,useResolvedAnchor as tt}from'../../internal/floating.js';import{FormFields as ot}from'../../internal/form-fields.js';import{useFrozenData as nt}from'../../internal/frozen.js';import{useProvidedId as it}from'../../internal/id.js';import{OpenClosedProvider as rt,State as q,useOpenClosed as lt}from'../../internal/open-closed.js';import{isDisabledReactIssue7711 as at}from'../../utils/bugs.js';import{Focus as v,calculateActiveIndex as ce}from'../../utils/calculate-active-index.js';import{disposables as st}from'../../utils/disposables.js';import{Focus as Oe,FocusableMode as pt,focusFrom as ut,isFocusableElement as dt,sortByDomNode as ct}from'../../utils/focus-management.js';import{attemptSubmit as ft}from'../../utils/form.js';import{match as G}from'../../utils/match.js';import{getOwnerDocument as bt}from'../../utils/owner.js';import{RenderFeatures as ye,forwardRefWithAs as j,mergeProps as ve,render as z}from'../../utils/render.js';import{useDescribedBy as Tt}from'../description/description.js';import{Keys as E}from'../keyboard.js';import{Label as mt,useLabelledBy as xt,useLabels as Ot}from'../label/label.js';import{Portal as yt}from'../portal/portal.js';var vt=(o=>(o[o.Open=0]="Open",o[o.Closed=1]="Closed",o))(vt||{}),gt=(o=>(o[o.Single=0]="Single",o[o.Multi=1]="Multi",o))(gt||{}),Lt=(o=>(o[o.Pointer=0]="Pointer",o[o.Other=1]="Other",o))(Lt||{}),St=(n=>(n[n.OpenListbox=0]="OpenListbox",n[n.CloseListbox=1]="CloseListbox",n[n.GoToOption=2]="GoToOption",n[n.Search=3]="Search",n[n.ClearSearch=4]="ClearSearch",n[n.RegisterOption=5]="RegisterOption",n[n.UnregisterOption=6]="UnregisterOption",n[n.SetButtonElement=7]="SetButtonElement",n[n.SetOptionsElement=8]="SetOptionsElement",n))(St||{});function fe(e,i=o=>o){let o=e.activeOptionIndex!==null?e.options[e.activeOptionIndex]:null,r=ct(i(e.options.slice()),m=>m.dataRef.current.domRef.current),a=o?r.indexOf(o):null;return a===-1&&(a=null),{options:r,activeOptionIndex:a}}let Et={[1](e){return e.dataRef.current.disabled||e.listboxState===1?e:{...e,activeOptionIndex:null,listboxState:1,__demoMode:!1}},[0](e){if(e.dataRef.current.disabled||e.listboxState===0)return e;let i=e.activeOptionIndex,{isSelected:o}=e.dataRef.current,r=e.options.findIndex(a=>o(a.dataRef.current.value));return r!==-1&&(i=r),{...e,listboxState:0,activeOptionIndex:i,__demoMode:!1}},[2](e,i){var m,x,d,p,n;if(e.dataRef.current.disabled||e.listboxState===1)return e;let o={...e,searchQuery:"",activationTrigger:(m=i.trigger)!=null?m:1,__demoMode:!1};if(i.focus===v.Nothing)return{...o,activeOptionIndex:null};if(i.focus===v.Specific)return{...o,activeOptionIndex:e.options.findIndex(u=>u.id===i.id)};if(i.focus===v.Previous){let u=e.activeOptionIndex;if(u!==null){let P=e.options[u].dataRef.current.domRef,t=ce(i,{resolveItems:()=>e.options,resolveActiveIndex:()=>e.activeOptionIndex,resolveId:s=>s.id,resolveDisabled:s=>s.dataRef.current.disabled});if(t!==null){let s=e.options[t].dataRef.current.domRef;if(((x=P.current)==null?void 0:x.previousElementSibling)===s.current||((d=s.current)==null?void 0:d.previousElementSibling)===null)return{...o,activeOptionIndex:t}}}}else if(i.focus===v.Next){let u=e.activeOptionIndex;if(u!==null){let P=e.options[u].dataRef.current.domRef,t=ce(i,{resolveItems:()=>e.options,resolveActiveIndex:()=>e.activeOptionIndex,resolveId:s=>s.id,resolveDisabled:s=>s.dataRef.current.disabled});if(t!==null){let s=e.options[t].dataRef.current.domRef;if(((p=P.current)==null?void 0:p.nextElementSibling)===s.current||((n=s.current)==null?void 0:n.nextElementSibling)===null)return{...o,activeOptionIndex:t}}}}let r=fe(e),a=ce(i,{resolveItems:()=>r.options,resolveActiveIndex:()=>r.activeOptionIndex,resolveId:u=>u.id,resolveDisabled:u=>u.dataRef.current.disabled});return{...o,...r,activeOptionIndex:a}},[3]:(e,i)=>{if(e.dataRef.current.disabled||e.listboxState===1)return e;let r=e.searchQuery!==""?0:1,a=e.searchQuery+i.value.toLowerCase(),x=(e.activeOptionIndex!==null?e.options.slice(e.activeOptionIndex+r).concat(e.options.slice(0,e.activeOptionIndex+r)):e.options).find(p=>{var n;return!p.dataRef.current.disabled&&((n=p.dataRef.current.textValue)==null?void 0:n.startsWith(a))}),d=x?e.options.indexOf(x):-1;return d===-1||d===e.activeOptionIndex?{...e,searchQuery:a}:{...e,searchQuery:a,activeOptionIndex:d,activationTrigger:1}},[4](e){return e.dataRef.current.disabled||e.listboxState===1||e.searchQuery===""?e:{...e,searchQuery:""}},[5]:(e,i)=>{let o={id:i.id,dataRef:i.dataRef},r=fe(e,a=>[...a,o]);return e.activeOptionIndex===null&&e.dataRef.current.isSelected(i.dataRef.current.value)&&(r.activeOptionIndex=r.options.indexOf(o)),{...e,...r}},[6]:(e,i)=>{let o=fe(e,r=>{let a=r.findIndex(m=>m.id===i.id);return a!==-1&&r.splice(a,1),r});return{...e,...o,activationTrigger:1}},[7]:(e,i)=>e.buttonElement===i.element?e:{...e,buttonElement:i.element},[8]:(e,i)=>e.optionsElement===i.element?e:{...e,optionsElement:i.element}},be=le(null);be.displayName="ListboxActionsContext";function Y(e){let i=se(be);if(i===null){let o=new Error(`<${e} /> is missing a parent <Listbox /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(o,Y),o}return i}let Z=le(null);Z.displayName="ListboxDataContext";function W(e){let i=se(Z);if(i===null){let o=new Error(`<${e} /> is missing a parent <Listbox /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(o,W),o}return i}function Pt(e,i){return G(i.type,Et,e,i)}let At=me;function Rt(e,i){var Te;let o=Je(),{value:r,defaultValue:a,form:m,name:x,onChange:d,by:p,invalid:n=!1,disabled:u=o||!1,horizontal:P=!1,multiple:t=!1,__demoMode:s=!1,...F}=e;const M=P?"horizontal":"vertical";let D=K(i),_=Be(a),[O=t?[]:void 0,g]=Me(r,d,_),[R,y]=_e(Pt,{dataRef:he(),listboxState:s?0:1,options:[],searchQuery:"",activeOptionIndex:null,activationTrigger:1,optionsVisible:!1,buttonElement:null,optionsElement:null,__demoMode:s}),B=pe({static:!1,hold:!1}),w=pe(new Map),f=Fe(p),A=ae(b=>G(c.mode,{[1]:()=>O.some(S=>f(S,b)),[0]:()=>f(O,b)}),[O]),c=k(()=>({...R,value:O,disabled:u,invalid:n,mode:t?1:0,orientation:M,compare:f,isSelected:A,optionsPropsRef:B,listRef:w}),[O,u,n,t,R,w]);de(()=>{R.dataRef.current=c},[c]);let L=c.listboxState===0;Ge(L,[c.buttonElement,c.optionsElement],(b,S)=>{var C;y({type:1}),dt(S,pt.Loose)||(b.preventDefault(),(C=c.buttonElement)==null||C.focus())});let N=k(()=>({open:c.listboxState===0,disabled:u,invalid:n,value:O}),[c,u,O,n]),ee=T(b=>{let S=c.options.find(C=>C.id===b);S&&V(S.dataRef.current.value)}),te=T(()=>{if(c.activeOptionIndex!==null){let{dataRef:b,id:S}=c.options[c.activeOptionIndex];V(b.current.value),y({type:2,focus:v.Specific,id:S})}}),oe=T(()=>y({type:0})),Q=T(()=>y({type:1})),X=xe(),ne=T((b,S,C)=>{X.dispose(),X.microTask(()=>b===v.Specific?y({type:2,focus:v.Specific,id:S,trigger:C}):y({type:2,focus:b,trigger:C}))}),ie=T((b,S)=>(y({type:5,id:b,dataRef:S}),()=>y({type:6,id:b}))),V=T(b=>G(c.mode,{[0](){return g==null?void 0:g(b)},[1](){let S=c.value.slice(),C=S.findIndex(Pe=>f(Pe,b));return C===-1?S.push(b):S.splice(C,1),g==null?void 0:g(S)}})),J=T(b=>y({type:3,value:b})),$=T(()=>y({type:4})),l=T(b=>{y({type:7,element:b})}),I=T(b=>{y({type:8,element:b})}),H=k(()=>({onChange:V,registerOption:ie,goToOption:ne,closeListbox:Q,openListbox:oe,selectActiveOption:te,selectOption:ee,search:J,clearSearch:$,setButtonElement:l,setOptionsElement:I}),[]),[re,Le]=Ot({inherit:!0}),Se={ref:D},Ee=ae(()=>{if(_!==void 0)return g==null?void 0:g(_)},[g,_]);return h.createElement(Le,{value:re,props:{htmlFor:(Te=c.buttonElement)==null?void 0:Te.id},slot:{open:c.listboxState===0,disabled:u}},h.createElement($e,null,h.createElement(be.Provider,{value:H},h.createElement(Z.Provider,{value:c},h.createElement(rt,{value:G(c.listboxState,{[0]:q.Open,[1]:q.Closed})},x!=null&&O!=null&&h.createElement(ot,{disabled:u,data:{[x]:O},form:m,onReset:Ee}),z({ourProps:Se,theirProps:F,slot:N,defaultTag:At,name:"Listbox"}))))))}let ht="button";function Dt(e,i){var c;let o=W("Listbox.Button"),r=Y("Listbox.Button"),a=ue(),m=it(),{id:x=m||`headlessui-listbox-button-${a}`,disabled:d=o.disabled||!1,autoFocus:p=!1,...n}=e,u=K(i,Ze(),r.setButtonElement),P=et(),t=T(L=>{switch(L.key){case E.Enter:ft(L.currentTarget);break;case E.Space:case E.ArrowDown:L.preventDefault(),U(()=>r.openListbox()),o.value||r.goToOption(v.First);break;case E.ArrowUp:L.preventDefault(),U(()=>r.openListbox()),o.value||r.goToOption(v.Last);break}}),s=T(L=>{switch(L.key){case E.Space:L.preventDefault();break}}),F=T(L=>{var N;if(at(L.currentTarget))return L.preventDefault();o.listboxState===0?(U(()=>r.closeListbox()),(N=o.buttonElement)==null||N.focus({preventScroll:!0})):(L.preventDefault(),r.openListbox())}),M=T(L=>L.preventDefault()),D=xt([x]),_=Tt(),{isFocusVisible:O,focusProps:g}=Ae({autoFocus:p}),{isHovered:R,hoverProps:y}=Re({isDisabled:d}),{pressed:B,pressProps:w}=Ce({disabled:d}),f=k(()=>({open:o.listboxState===0,active:B||o.listboxState===0,disabled:d,invalid:o.invalid,value:o.value,hover:R,focus:O,autofocus:p}),[o.listboxState,o.value,d,R,O,B,o.invalid,p]),A=ve(P(),{ref:u,id:x,type:Ke(e,o.buttonElement),"aria-haspopup":"listbox","aria-controls":(c=o.optionsElement)==null?void 0:c.id,"aria-expanded":o.listboxState===0,"aria-labelledby":D,"aria-describedby":_,disabled:d||void 0,autoFocus:p,onKeyDown:t,onKeyUp:s,onKeyPress:M,onClick:F},g,y,w);return z({ourProps:A,theirProps:n,slot:f,defaultTag:ht,name:"Listbox.Button"})}let ge=le(!1),_t="div",It=ye.RenderStrategy|ye.Static;function Ct(e,i){var J,$;let o=ue(),{id:r=`headlessui-listbox-options-${o}`,anchor:a,portal:m=!1,modal:x=!0,transition:d=!1,...p}=e,n=tt(a),[u,P]=Ie(null);n&&(m=!0);let t=W("Listbox.Options"),s=Y("Listbox.Options"),F=Ve(t.optionsElement),M=lt(),[D,_]=Xe(d,u,M!==null?(M&q.Open)===q.Open:t.listboxState===0);He(D,t.buttonElement,s.closeListbox);let O=t.__demoMode?!1:x&&t.listboxState===0;je(O,F);let g=t.__demoMode?!1:x&&t.listboxState===0;Ue(g,{allowed:ae(()=>[t.buttonElement,t.optionsElement],[t.buttonElement,t.optionsElement])});let R=t.listboxState!==0,B=we(R,t.buttonElement)?!1:D,w=D&&t.listboxState===1,f=nt(w,t.value),A=T(l=>t.compare(f,l)),c=k(()=>{var I;if(n==null||!((I=n==null?void 0:n.to)!=null&&I.includes("selection")))return null;let l=t.options.findIndex(H=>A(H.dataRef.current.value));return l===-1&&(l=0),l},[n,t.options]),L=(()=>{if(n==null)return;if(c===null)return{...n,inner:void 0};let l=Array.from(t.listRef.current.values());return{...n,inner:{listRef:{current:l},index:c}}})(),[N,ee]=qe(L),te=Ye(),oe=K(i,n?N:null,s.setOptionsElement,P),Q=xe();De(()=>{var I;let l=t.optionsElement;l&&t.listboxState===0&&l!==((I=bt(l))==null?void 0:I.activeElement)&&(l==null||l.focus({preventScroll:!0}))},[t.listboxState,t.optionsElement]);let X=T(l=>{var I,H;switch(Q.dispose(),l.key){case E.Space:if(t.searchQuery!=="")return l.preventDefault(),l.stopPropagation(),s.search(l.key);case E.Enter:if(l.preventDefault(),l.stopPropagation(),t.activeOptionIndex!==null){let{dataRef:re}=t.options[t.activeOptionIndex];s.onChange(re.current.value)}t.mode===0&&(U(()=>s.closeListbox()),(I=t.buttonElement)==null||I.focus({preventScroll:!0}));break;case G(t.orientation,{vertical:E.ArrowDown,horizontal:E.ArrowRight}):return l.preventDefault(),l.stopPropagation(),s.goToOption(v.Next);case G(t.orientation,{vertical:E.ArrowUp,horizontal:E.ArrowLeft}):return l.preventDefault(),l.stopPropagation(),s.goToOption(v.Previous);case E.Home:case E.PageUp:return l.preventDefault(),l.stopPropagation(),s.goToOption(v.First);case E.End:case E.PageDown:return l.preventDefault(),l.stopPropagation(),s.goToOption(v.Last);case E.Escape:l.preventDefault(),l.stopPropagation(),U(()=>s.closeListbox()),(H=t.buttonElement)==null||H.focus({preventScroll:!0});return;case E.Tab:l.preventDefault(),l.stopPropagation(),U(()=>s.closeListbox()),ut(t.buttonElement,l.shiftKey?Oe.Previous:Oe.Next);break;default:l.key.length===1&&(s.search(l.key),Q.setTimeout(()=>s.clearSearch(),350));break}}),ne=(J=t.buttonElement)==null?void 0:J.id,ie=k(()=>({open:t.listboxState===0}),[t.listboxState]),V=ve(n?te():{},{id:r,ref:oe,"aria-activedescendant":t.activeOptionIndex===null||($=t.options[t.activeOptionIndex])==null?void 0:$.id,"aria-multiselectable":t.mode===1?!0:void 0,"aria-labelledby":ne,"aria-orientation":t.orientation,onKeyDown:X,role:"listbox",tabIndex:t.listboxState===0?0:void 0,style:{...p.style,...ee,"--button-width":ke(t.buttonElement,!0).width},...Qe(_)});return h.createElement(yt,{enabled:m?e.static||D:!1},h.createElement(Z.Provider,{value:t.mode===1?t:{...t,isSelected:A}},z({ourProps:V,theirProps:p,slot:ie,defaultTag:_t,features:It,visible:B,name:"Listbox.Options"})))}let Ft="div";function Mt(e,i){let o=ue(),{id:r=`headlessui-listbox-option-${o}`,disabled:a=!1,value:m,...x}=e,d=se(ge)===!0,p=W("Listbox.Option"),n=Y("Listbox.Option"),u=p.activeOptionIndex!==null?p.options[p.activeOptionIndex].id===r:!1,P=p.isSelected(m),t=pe(null),s=ze(t),F=Ne({disabled:a,value:m,domRef:t,get textValue(){return s()}}),M=K(i,t,f=>{f?p.listRef.current.set(r,f):p.listRef.current.delete(r)});de(()=>{if(!p.__demoMode&&p.listboxState===0&&u&&p.activationTrigger!==0)return st().requestAnimationFrame(()=>{var f,A;(A=(f=t.current)==null?void 0:f.scrollIntoView)==null||A.call(f,{block:"nearest"})})},[t,u,p.__demoMode,p.listboxState,p.activationTrigger,p.activeOptionIndex]),de(()=>{if(!d)return n.registerOption(r,F)},[F,r,d]);let D=T(f=>{var A;if(a)return f.preventDefault();n.onChange(m),p.mode===0&&(U(()=>n.closeListbox()),(A=p.buttonElement)==null||A.focus({preventScroll:!0}))}),_=T(()=>{if(a)return n.goToOption(v.Nothing);n.goToOption(v.Specific,r)}),O=We(),g=T(f=>{O.update(f),!a&&(u||n.goToOption(v.Specific,r,0))}),R=T(f=>{O.wasMoved(f)&&(a||u||n.goToOption(v.Specific,r,0))}),y=T(f=>{O.wasMoved(f)&&(a||u&&n.goToOption(v.Nothing))}),B=k(()=>({active:u,focus:u,selected:P,disabled:a,selectedOption:P&&d}),[u,P,a,d]),w=d?{}:{id:r,ref:M,role:"option",tabIndex:a===!0?void 0:-1,"aria-disabled":a===!0?!0:void 0,"aria-selected":P,disabled:void 0,onClick:D,onFocus:_,onPointerEnter:g,onMouseEnter:g,onPointerMove:R,onMouseMove:R,onPointerLeave:y,onMouseLeave:y};return!P&&d?null:z({ourProps:w,theirProps:x,slot:B,defaultTag:Ft,name:"Listbox.Option"})}let Bt=me;function wt(e,i){let{options:o,placeholder:r,...a}=e,x={ref:K(i)},d=W("ListboxSelectedOption"),p=k(()=>({}),[]),n=d.value===void 0||d.value===null||d.mode===1&&Array.isArray(d.value)&&d.value.length===0;return h.createElement(ge.Provider,{value:!0},z({ourProps:x,theirProps:{...a,children:h.createElement(h.Fragment,null,r&&n?r:o)},slot:p,defaultTag:Bt,name:"ListboxSelectedOption"}))}let kt=j(Rt),Ut=j(Dt),Nt=mt,Ht=j(Ct),Gt=j(Mt),Vt=j(wt),Fo=Object.assign(kt,{Button:Ut,Label:Nt,Options:Ht,Option:Gt,SelectedOption:Vt});export{Fo as Listbox,Ut as ListboxButton,Nt as ListboxLabel,Gt as ListboxOption,Ht as ListboxOptions,Vt as ListboxSelectedOption}; |
@@ -1,1 +0,1 @@ | ||
"use client";import{useFocusRing as Le}from"@react-aria/focus";import{useHover as Ie}from"@react-aria/interactions";import E,{createContext as oe,createRef as Pe,useContext as re,useEffect as ne,useMemo as D,useReducer as De,useRef as ee,useState as le}from"react";import{useActivePress as he}from'../../hooks/use-active-press.js';import{useElementSize as ke}from'../../hooks/use-element-size.js';import{useEvent as g}from'../../hooks/use-event.js';import{useEventListener as Ge}from'../../hooks/use-event-listener.js';import{useId as ae}from'../../hooks/use-id.js';import{useIsoMorphicEffect as He}from'../../hooks/use-iso-morphic-effect.js';import{useLatestValue as Ae}from'../../hooks/use-latest-value.js';import{useOnDisappear as Ue}from'../../hooks/use-on-disappear.js';import{useOutsideClick as Ne}from'../../hooks/use-outside-click.js';import{useOwnerDocument as fe}from'../../hooks/use-owner.js';import{useResolveButtonType as we}from'../../hooks/use-resolve-button-type.js';import{MainTreeProvider as Ce,useMainTreeNode as Ke,useRootContainers as We}from'../../hooks/use-root-containers.js';import{useScrollLock as je}from'../../hooks/use-scroll-lock.js';import{optionalRef as Ve,useSyncRefs as q}from'../../hooks/use-sync-refs.js';import{Direction as k,useTabDirection as Be}from'../../hooks/use-tab-direction.js';import{transitionDataAttributes as Re,useTransition as _e}from'../../hooks/use-transition.js';import{CloseProvider as $e}from'../../internal/close-provider.js';import{FloatingProvider as Je,useFloatingPanel as Xe,useFloatingPanelProps as qe,useFloatingReference as ze,useResolvedAnchor as Ye}from'../../internal/floating.js';import{Hidden as ce,HiddenFeatures as ve}from'../../internal/hidden.js';import{OpenClosedProvider as Qe,ResetOpenClosedProvider as Ze,State as z,useOpenClosed as Fe}from'../../internal/open-closed.js';import{isDisabledReactIssue7711 as xe}from'../../utils/bugs.js';import{Focus as G,FocusResult as Te,FocusableMode as et,focusIn as W,getFocusableElements as me,isFocusableElement as tt}from'../../utils/focus-management.js';import{match as j}from'../../utils/match.js';import'../../utils/micro-task.js';import{getOwnerDocument as ot}from'../../utils/owner.js';import{RenderFeatures as pe,forwardRefWithAs as Y,mergeProps as ye,render as te,useMergeRefsFn as rt}from'../../utils/render.js';import{Keys as V}from'../keyboard.js';import{Portal as nt,useNestedPortals as lt}from'../portal/portal.js';var at=(P=>(P[P.Open=0]="Open",P[P.Closed=1]="Closed",P))(at||{}),pt=(s=>(s[s.TogglePopover=0]="TogglePopover",s[s.ClosePopover=1]="ClosePopover",s[s.SetButton=2]="SetButton",s[s.SetButtonId=3]="SetButtonId",s[s.SetPanel=4]="SetPanel",s[s.SetPanelId=5]="SetPanelId",s))(pt||{});let st={[0]:t=>({...t,popoverState:j(t.popoverState,{[0]:1,[1]:0}),__demoMode:!1}),[1](t){return t.popoverState===1?t:{...t,popoverState:1,__demoMode:!1}},[2](t,n){return t.button===n.button?t:{...t,button:n.button}},[3](t,n){return t.buttonId===n.buttonId?t:{...t,buttonId:n.buttonId}},[4](t,n){return t.panel===n.panel?t:{...t,panel:n.panel}},[5](t,n){return t.panelId===n.panelId?t:{...t,panelId:n.panelId}}},Ee=oe(null);Ee.displayName="PopoverContext";function se(t){let n=re(Ee);if(n===null){let P=new Error(`<${t} /> is missing a parent <Popover /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(P,se),P}return n}let ue=oe(null);ue.displayName="PopoverAPIContext";function be(t){let n=re(ue);if(n===null){let P=new Error(`<${t} /> is missing a parent <Popover /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(P,be),P}return n}let ge=oe(null);ge.displayName="PopoverGroupContext";function Me(){return re(ge)}let ie=oe(null);ie.displayName="PopoverPanelContext";function ut(){return re(ie)}function it(t,n){return j(n.type,st,t,n)}let dt="div";function Pt(t,n){var w;let{__demoMode:P=!1,...C}=t,m=ee(null),A=q(n,Ve(l=>{m.current=l})),s=ee([]),r=De(it,{__demoMode:P,popoverState:P?0:1,buttons:s,button:null,buttonId:null,panel:null,panelId:null,beforePanelSentinel:Pe(),afterPanelSentinel:Pe(),afterButtonSentinel:Pe()}),[{popoverState:T,button:d,buttonId:o,panel:u,panelId:B,beforePanelSentinel:y,afterPanelSentinel:b,afterButtonSentinel:i},a]=r,c=fe((w=m.current)!=null?w:d),L=D(()=>{if(!d||!u)return!1;for(let S of document.querySelectorAll("body > *"))if(Number(S==null?void 0:S.contains(d))^Number(S==null?void 0:S.contains(u)))return!0;let l=me(),e=l.indexOf(d),p=(e+l.length-1)%l.length,f=(e+1)%l.length,v=l[p],O=l[f];return!u.contains(v)&&!u.contains(O)},[d,u]),_=Ae(o),H=Ae(B),I=D(()=>({buttonId:_,panelId:H,close:()=>a({type:1})}),[_,H,a]),M=Me(),h=M==null?void 0:M.registerPopover,R=g(()=>{var l;return(l=M==null?void 0:M.isFocusWithinPopoverGroup())!=null?l:(c==null?void 0:c.activeElement)&&((d==null?void 0:d.contains(c.activeElement))||(u==null?void 0:u.contains(c.activeElement)))});ne(()=>h==null?void 0:h(I),[h,I]);let[$,U]=lt(),F=Ke(d),N=We({mainTreeNode:F,portals:$,defaultContainers:[d,u]});Ge(c==null?void 0:c.defaultView,"focus",l=>{var e,p,f,v,O,S;l.target!==window&&l.target instanceof HTMLElement&&T===0&&(R()||d&&u&&(N.contains(l.target)||(p=(e=y.current)==null?void 0:e.contains)!=null&&p.call(e,l.target)||(v=(f=b.current)==null?void 0:f.contains)!=null&&v.call(f,l.target)||(S=(O=i.current)==null?void 0:O.contains)!=null&&S.call(O,l.target)||a({type:1})))},!0),Ne(T===0,N.resolveContainers,(l,e)=>{a({type:1}),tt(e,et.Loose)||(l.preventDefault(),d==null||d.focus())});let x=g(l=>{a({type:1});let e=(()=>l?l instanceof HTMLElement?l:"current"in l&&l.current instanceof HTMLElement?l.current:d:d)();e==null||e.focus()}),Z=D(()=>({close:x,isPortalled:L}),[x,L]),J=D(()=>({open:T===0,close:x}),[T,x]),X={ref:A};return E.createElement(Ce,{node:F},E.createElement(Je,null,E.createElement(ie.Provider,{value:null},E.createElement(Ee.Provider,{value:r},E.createElement(ue.Provider,{value:Z},E.createElement($e,{value:x},E.createElement(Qe,{value:j(T,{[0]:z.Open,[1]:z.Closed})},E.createElement(U,null,te({ourProps:X,theirProps:C,slot:J,defaultTag:dt,name:"Popover"})))))))))}let ft="button";function ct(t,n){let P=ae(),{id:C=`headlessui-popover-button-${P}`,disabled:m=!1,autoFocus:A=!1,...s}=t,[r,T]=se("Popover.Button"),{isPortalled:d}=be("Popover.Button"),o=ee(null),u=`headlessui-focus-sentinel-${ae()}`,B=Me(),y=B==null?void 0:B.closeOthers,i=ut()!==null;ne(()=>{if(!i)return T({type:3,buttonId:C}),()=>{T({type:3,buttonId:null})}},[i,C,T]);let[a]=le(()=>Symbol()),c=q(o,n,ze(),i?null:g(e=>{if(e)r.buttons.current.push(a);else{let p=r.buttons.current.indexOf(a);p!==-1&&r.buttons.current.splice(p,1)}r.buttons.current.length>1&&console.warn("You are already using a <Popover.Button /> but only 1 <Popover.Button /> is supported."),e&&T({type:2,button:e})})),L=q(o,n),_=fe(o),H=g(e=>{var p,f,v;if(i){if(r.popoverState===1)return;switch(e.key){case V.Space:case V.Enter:e.preventDefault(),(f=(p=e.target).click)==null||f.call(p),T({type:1}),(v=r.button)==null||v.focus();break}}else switch(e.key){case V.Space:case V.Enter:e.preventDefault(),e.stopPropagation(),r.popoverState===1&&(y==null||y(r.buttonId)),T({type:0});break;case V.Escape:if(r.popoverState!==0)return y==null?void 0:y(r.buttonId);if(!o.current||_!=null&&_.activeElement&&!o.current.contains(_.activeElement))return;e.preventDefault(),e.stopPropagation(),T({type:1});break}}),I=g(e=>{i||e.key===V.Space&&e.preventDefault()}),M=g(e=>{var p,f;xe(e.currentTarget)||m||(i?(T({type:1}),(p=r.button)==null||p.focus()):(e.preventDefault(),e.stopPropagation(),r.popoverState===1&&(y==null||y(r.buttonId)),T({type:0}),(f=r.button)==null||f.focus()))}),h=g(e=>{e.preventDefault(),e.stopPropagation()}),{isFocusVisible:R,focusProps:$}=Le({autoFocus:A}),{isHovered:U,hoverProps:F}=Ie({isDisabled:m}),{pressed:N,pressProps:Q}=he({disabled:m}),x=r.popoverState===0,Z=D(()=>({open:x,active:N||x,disabled:m,hover:U,focus:R,autofocus:A}),[x,U,R,N,m,A]),J=we(t,r.button),X=i?ye({ref:L,type:J,onKeyDown:H,onClick:M,disabled:m||void 0,autoFocus:A},$,F,Q):ye({ref:c,id:r.buttonId,type:J,"aria-expanded":r.popoverState===0,"aria-controls":r.panel?r.panelId:void 0,disabled:m||void 0,autoFocus:A,onKeyDown:H,onKeyUp:I,onClick:M,onMouseDown:h},$,F,Q),w=Be(),l=g(()=>{let e=r.panel;if(!e)return;function p(){j(w.current,{[k.Forwards]:()=>W(e,G.First),[k.Backwards]:()=>W(e,G.Last)})===Te.Error&&W(me().filter(v=>v.dataset.headlessuiFocusGuard!=="true"),j(w.current,{[k.Forwards]:G.Next,[k.Backwards]:G.Previous}),{relativeTo:r.button})}p()});return E.createElement(E.Fragment,null,te({ourProps:X,theirProps:s,slot:Z,defaultTag:ft,name:"Popover.Button"}),x&&!i&&d&&E.createElement(ce,{id:u,ref:r.afterButtonSentinel,features:ve.Focusable,"data-headlessui-focus-guard":!0,as:"button",type:"button",onFocus:l}))}let vt="div",Tt=pe.RenderStrategy|pe.Static;function Oe(t,n){let P=ae(),{id:C=`headlessui-popover-backdrop-${P}`,transition:m=!1,...A}=t,[{popoverState:s},r]=se("Popover.Backdrop"),[T,d]=le(null),o=q(n,d),u=Fe(),[B,y]=_e(m,T,u!==null?(u&z.Open)===z.Open:s===0),b=g(c=>{if(xe(c.currentTarget))return c.preventDefault();r({type:1})}),i=D(()=>({open:s===0}),[s]),a={ref:o,id:C,"aria-hidden":!0,onClick:b,...Re(y)};return te({ourProps:a,theirProps:A,slot:i,defaultTag:vt,features:Tt,visible:B,name:"Popover.Backdrop"})}let mt="div",yt=pe.RenderStrategy|pe.Static;function Et(t,n){let P=ae(),{id:C=`headlessui-popover-panel-${P}`,focus:m=!1,anchor:A,portal:s=!1,modal:r=!1,transition:T=!1,...d}=t,[o,u]=se("Popover.Panel"),{close:B,isPortalled:y}=be("Popover.Panel"),b=`headlessui-focus-sentinel-before-${P}`,i=`headlessui-focus-sentinel-after-${P}`,a=ee(null),c=Ye(A),[L,_]=Xe(c),H=qe();c&&(s=!0);let[I,M]=le(null),h=q(a,n,c?L:null,g(e=>u({type:4,panel:e})),M),R=fe(a),$=rt();He(()=>(u({type:5,panelId:C}),()=>{u({type:5,panelId:null})}),[C,u]);let U=Fe(),[F,N]=_e(T,I,U!==null?(U&z.Open)===z.Open:o.popoverState===0);Ue(F,o.button,()=>{u({type:1})});let Q=o.__demoMode?!1:r&&F;je(Q,R);let x=g(e=>{var p;switch(e.key){case V.Escape:if(o.popoverState!==0||!a.current||R!=null&&R.activeElement&&!a.current.contains(R.activeElement))return;e.preventDefault(),e.stopPropagation(),u({type:1}),(p=o.button)==null||p.focus();break}});ne(()=>{var e;t.static||o.popoverState===1&&((e=t.unmount)==null||e)&&u({type:4,panel:null})},[o.popoverState,t.unmount,t.static,u]),ne(()=>{if(o.__demoMode||!m||o.popoverState!==0||!a.current)return;let e=R==null?void 0:R.activeElement;a.current.contains(e)||W(a.current,G.First)},[o.__demoMode,m,a.current,o.popoverState]);let Z=D(()=>({open:o.popoverState===0,close:B}),[o.popoverState,B]),J=ye(c?H():{},{ref:h,id:C,onKeyDown:x,onBlur:m&&o.popoverState===0?e=>{var f,v,O,S,K;let p=e.relatedTarget;p&&a.current&&((f=a.current)!=null&&f.contains(p)||(u({type:1}),((O=(v=o.beforePanelSentinel.current)==null?void 0:v.contains)!=null&&O.call(v,p)||(K=(S=o.afterPanelSentinel.current)==null?void 0:S.contains)!=null&&K.call(S,p))&&p.focus({preventScroll:!0})))}:void 0,tabIndex:-1,style:{...d.style,..._,"--button-width":ke(o.button,!0).width},...Re(N)}),X=Be(),w=g(()=>{let e=a.current;if(!e)return;function p(){j(X.current,{[k.Forwards]:()=>{var v;W(e,G.First)===Te.Error&&((v=o.afterPanelSentinel.current)==null||v.focus())},[k.Backwards]:()=>{var f;(f=o.button)==null||f.focus({preventScroll:!0})}})}p()}),l=g(()=>{let e=a.current;if(!e)return;function p(){j(X.current,{[k.Forwards]:()=>{if(!o.button)return;let f=me(),v=f.indexOf(o.button),O=f.slice(0,v+1),K=[...f.slice(v+1),...O];for(let de of K.slice())if(de.dataset.headlessuiFocusGuard==="true"||I!=null&&I.contains(de)){let Se=K.indexOf(de);Se!==-1&&K.splice(Se,1)}W(K,G.First,{sorted:!1})},[k.Backwards]:()=>{var v;W(e,G.Previous)===Te.Error&&((v=o.button)==null||v.focus())}})}p()});return E.createElement(Ze,null,E.createElement(ie.Provider,{value:C},E.createElement(ue.Provider,{value:{close:B,isPortalled:y}},E.createElement(nt,{enabled:s?t.static||F:!1},F&&y&&E.createElement(ce,{id:b,ref:o.beforePanelSentinel,features:ve.Focusable,"data-headlessui-focus-guard":!0,as:"button",type:"button",onFocus:w}),te({mergeRefs:$,ourProps:J,theirProps:d,slot:Z,defaultTag:mt,features:yt,visible:F,name:"Popover.Panel"}),F&&y&&E.createElement(ce,{id:i,ref:o.afterPanelSentinel,features:ve.Focusable,"data-headlessui-focus-guard":!0,as:"button",type:"button",onFocus:l})))))}let bt="div";function gt(t,n){let P=ee(null),C=q(P,n),[m,A]=le([]),s=g(b=>{A(i=>{let a=i.indexOf(b);if(a!==-1){let c=i.slice();return c.splice(a,1),c}return i})}),r=g(b=>(A(i=>[...i,b]),()=>s(b))),T=g(()=>{var a;let b=ot(P);if(!b)return!1;let i=b.activeElement;return(a=P.current)!=null&&a.contains(i)?!0:m.some(c=>{var L,_;return((L=b.getElementById(c.buttonId.current))==null?void 0:L.contains(i))||((_=b.getElementById(c.panelId.current))==null?void 0:_.contains(i))})}),d=g(b=>{for(let i of m)i.buttonId.current!==b&&i.close()}),o=D(()=>({registerPopover:r,unregisterPopover:s,isFocusWithinPopoverGroup:T,closeOthers:d}),[r,s,T,d]),u=D(()=>({}),[]),B=t,y={ref:C};return E.createElement(Ce,null,E.createElement(ge.Provider,{value:o},te({ourProps:y,theirProps:B,slot:u,defaultTag:bt,name:"Popover.Group"})))}let St=Y(Pt),At=Y(ct),Ct=Y(Oe),Bt=Y(Oe),Rt=Y(Et),_t=Y(gt),ao=Object.assign(St,{Button:At,Backdrop:Bt,Overlay:Ct,Panel:Rt,Group:_t});export{ao as Popover,Bt as PopoverBackdrop,At as PopoverButton,_t as PopoverGroup,Ct as PopoverOverlay,Rt as PopoverPanel}; | ||
"use client";import{useFocusRing as Le}from"@react-aria/focus";import{useHover as Ie}from"@react-aria/interactions";import E,{createContext as oe,createRef as Pe,useContext as re,useEffect as ne,useMemo as D,useReducer as De,useRef as ee,useState as le}from"react";import{useActivePress as he}from'../../hooks/use-active-press.js';import{useElementSize as ke}from'../../hooks/use-element-size.js';import{useEvent as g}from'../../hooks/use-event.js';import{useEventListener as Ge}from'../../hooks/use-event-listener.js';import{useId as ae}from'../../hooks/use-id.js';import{useIsoMorphicEffect as He}from'../../hooks/use-iso-morphic-effect.js';import{useLatestValue as Ae}from'../../hooks/use-latest-value.js';import{useOnDisappear as Ue}from'../../hooks/use-on-disappear.js';import{useOutsideClick as Ne}from'../../hooks/use-outside-click.js';import{useOwnerDocument as fe}from'../../hooks/use-owner.js';import{useResolveButtonType as we}from'../../hooks/use-resolve-button-type.js';import{MainTreeProvider as Ce,useMainTreeNode as Ke,useRootContainers as We}from'../../hooks/use-root-containers.js';import{useScrollLock as je}from'../../hooks/use-scroll-lock.js';import{optionalRef as Ve,useSyncRefs as q}from'../../hooks/use-sync-refs.js';import{Direction as k,useTabDirection as Be}from'../../hooks/use-tab-direction.js';import{transitionDataAttributes as Re,useTransition as _e}from'../../hooks/use-transition.js';import{CloseProvider as $e}from'../../internal/close-provider.js';import{FloatingProvider as Je,useFloatingPanel as Xe,useFloatingPanelProps as qe,useFloatingReference as ze,useResolvedAnchor as Ye}from'../../internal/floating.js';import{Hidden as ce,HiddenFeatures as ve}from'../../internal/hidden.js';import{OpenClosedProvider as Qe,ResetOpenClosedProvider as Ze,State as z,useOpenClosed as Fe}from'../../internal/open-closed.js';import{isDisabledReactIssue7711 as xe}from'../../utils/bugs.js';import{Focus as G,FocusResult as Te,FocusableMode as et,focusIn as W,getFocusableElements as me,isFocusableElement as tt}from'../../utils/focus-management.js';import{match as j}from'../../utils/match.js';import'../../utils/micro-task.js';import{getOwnerDocument as ot}from'../../utils/owner.js';import{RenderFeatures as pe,forwardRefWithAs as Y,mergeProps as ye,render as te,useMergeRefsFn as rt}from'../../utils/render.js';import{Keys as V}from'../keyboard.js';import{Portal as nt,useNestedPortals as lt}from'../portal/portal.js';var at=(P=>(P[P.Open=0]="Open",P[P.Closed=1]="Closed",P))(at||{}),pt=(s=>(s[s.TogglePopover=0]="TogglePopover",s[s.ClosePopover=1]="ClosePopover",s[s.SetButton=2]="SetButton",s[s.SetButtonId=3]="SetButtonId",s[s.SetPanel=4]="SetPanel",s[s.SetPanelId=5]="SetPanelId",s))(pt||{});let st={[0]:t=>({...t,popoverState:j(t.popoverState,{[0]:1,[1]:0}),__demoMode:!1}),[1](t){return t.popoverState===1?t:{...t,popoverState:1,__demoMode:!1}},[2](t,n){return t.button===n.button?t:{...t,button:n.button}},[3](t,n){return t.buttonId===n.buttonId?t:{...t,buttonId:n.buttonId}},[4](t,n){return t.panel===n.panel?t:{...t,panel:n.panel}},[5](t,n){return t.panelId===n.panelId?t:{...t,panelId:n.panelId}}},Ee=oe(null);Ee.displayName="PopoverContext";function se(t){let n=re(Ee);if(n===null){let P=new Error(`<${t} /> is missing a parent <Popover /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(P,se),P}return n}let ue=oe(null);ue.displayName="PopoverAPIContext";function be(t){let n=re(ue);if(n===null){let P=new Error(`<${t} /> is missing a parent <Popover /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(P,be),P}return n}let ge=oe(null);ge.displayName="PopoverGroupContext";function Me(){return re(ge)}let ie=oe(null);ie.displayName="PopoverPanelContext";function ut(){return re(ie)}function it(t,n){return j(n.type,st,t,n)}let dt="div";function Pt(t,n){var w;let{__demoMode:P=!1,...C}=t,m=ee(null),A=q(n,Ve(l=>{m.current=l})),s=ee([]),r=De(it,{__demoMode:P,popoverState:P?0:1,buttons:s,button:null,buttonId:null,panel:null,panelId:null,beforePanelSentinel:Pe(),afterPanelSentinel:Pe(),afterButtonSentinel:Pe()}),[{popoverState:T,button:d,buttonId:o,panel:u,panelId:B,beforePanelSentinel:y,afterPanelSentinel:b,afterButtonSentinel:i},a]=r,c=fe((w=m.current)!=null?w:d),L=D(()=>{if(!d||!u)return!1;for(let S of document.querySelectorAll("body > *"))if(Number(S==null?void 0:S.contains(d))^Number(S==null?void 0:S.contains(u)))return!0;let l=me(),e=l.indexOf(d),p=(e+l.length-1)%l.length,f=(e+1)%l.length,v=l[p],O=l[f];return!u.contains(v)&&!u.contains(O)},[d,u]),_=Ae(o),H=Ae(B),I=D(()=>({buttonId:_,panelId:H,close:()=>a({type:1})}),[_,H,a]),M=Me(),h=M==null?void 0:M.registerPopover,R=g(()=>{var l;return(l=M==null?void 0:M.isFocusWithinPopoverGroup())!=null?l:(c==null?void 0:c.activeElement)&&((d==null?void 0:d.contains(c.activeElement))||(u==null?void 0:u.contains(c.activeElement)))});ne(()=>h==null?void 0:h(I),[h,I]);let[$,U]=lt(),F=Ke(d),N=We({mainTreeNode:F,portals:$,defaultContainers:[d,u]});Ge(c==null?void 0:c.defaultView,"focus",l=>{var e,p,f,v,O,S;l.target!==window&&l.target instanceof HTMLElement&&T===0&&(R()||d&&u&&(N.contains(l.target)||(p=(e=y.current)==null?void 0:e.contains)!=null&&p.call(e,l.target)||(v=(f=b.current)==null?void 0:f.contains)!=null&&v.call(f,l.target)||(S=(O=i.current)==null?void 0:O.contains)!=null&&S.call(O,l.target)||a({type:1})))},!0),Ne(T===0,N.resolveContainers,(l,e)=>{a({type:1}),tt(e,et.Loose)||(l.preventDefault(),d==null||d.focus())});let x=g(l=>{a({type:1});let e=(()=>l?l instanceof HTMLElement?l:"current"in l&&l.current instanceof HTMLElement?l.current:d:d)();e==null||e.focus()}),Z=D(()=>({close:x,isPortalled:L}),[x,L]),J=D(()=>({open:T===0,close:x}),[T,x]),X={ref:A};return E.createElement(Ce,{node:F},E.createElement(Je,null,E.createElement(ie.Provider,{value:null},E.createElement(Ee.Provider,{value:r},E.createElement(ue.Provider,{value:Z},E.createElement($e,{value:x},E.createElement(Qe,{value:j(T,{[0]:z.Open,[1]:z.Closed})},E.createElement(U,null,te({ourProps:X,theirProps:C,slot:J,defaultTag:dt,name:"Popover"})))))))))}let ft="button";function ct(t,n){let P=ae(),{id:C=`headlessui-popover-button-${P}`,disabled:m=!1,autoFocus:A=!1,...s}=t,[r,T]=se("Popover.Button"),{isPortalled:d}=be("Popover.Button"),o=ee(null),u=`headlessui-focus-sentinel-${ae()}`,B=Me(),y=B==null?void 0:B.closeOthers,i=ut()!==null;ne(()=>{if(!i)return T({type:3,buttonId:C}),()=>{T({type:3,buttonId:null})}},[i,C,T]);let[a]=le(()=>Symbol()),c=q(o,n,ze(),g(e=>{if(!i){if(e)r.buttons.current.push(a);else{let p=r.buttons.current.indexOf(a);p!==-1&&r.buttons.current.splice(p,1)}r.buttons.current.length>1&&console.warn("You are already using a <Popover.Button /> but only 1 <Popover.Button /> is supported."),e&&T({type:2,button:e})}})),L=q(o,n),_=fe(o),H=g(e=>{var p,f,v;if(i){if(r.popoverState===1)return;switch(e.key){case V.Space:case V.Enter:e.preventDefault(),(f=(p=e.target).click)==null||f.call(p),T({type:1}),(v=r.button)==null||v.focus();break}}else switch(e.key){case V.Space:case V.Enter:e.preventDefault(),e.stopPropagation(),r.popoverState===1&&(y==null||y(r.buttonId)),T({type:0});break;case V.Escape:if(r.popoverState!==0)return y==null?void 0:y(r.buttonId);if(!o.current||_!=null&&_.activeElement&&!o.current.contains(_.activeElement))return;e.preventDefault(),e.stopPropagation(),T({type:1});break}}),I=g(e=>{i||e.key===V.Space&&e.preventDefault()}),M=g(e=>{var p,f;xe(e.currentTarget)||m||(i?(T({type:1}),(p=r.button)==null||p.focus()):(e.preventDefault(),e.stopPropagation(),r.popoverState===1&&(y==null||y(r.buttonId)),T({type:0}),(f=r.button)==null||f.focus()))}),h=g(e=>{e.preventDefault(),e.stopPropagation()}),{isFocusVisible:R,focusProps:$}=Le({autoFocus:A}),{isHovered:U,hoverProps:F}=Ie({isDisabled:m}),{pressed:N,pressProps:Q}=he({disabled:m}),x=r.popoverState===0,Z=D(()=>({open:x,active:N||x,disabled:m,hover:U,focus:R,autofocus:A}),[x,U,R,N,m,A]),J=we(t,r.button),X=i?ye({ref:L,type:J,onKeyDown:H,onClick:M,disabled:m||void 0,autoFocus:A},$,F,Q):ye({ref:c,id:r.buttonId,type:J,"aria-expanded":r.popoverState===0,"aria-controls":r.panel?r.panelId:void 0,disabled:m||void 0,autoFocus:A,onKeyDown:H,onKeyUp:I,onClick:M,onMouseDown:h},$,F,Q),w=Be(),l=g(()=>{let e=r.panel;if(!e)return;function p(){j(w.current,{[k.Forwards]:()=>W(e,G.First),[k.Backwards]:()=>W(e,G.Last)})===Te.Error&&W(me().filter(v=>v.dataset.headlessuiFocusGuard!=="true"),j(w.current,{[k.Forwards]:G.Next,[k.Backwards]:G.Previous}),{relativeTo:r.button})}p()});return E.createElement(E.Fragment,null,te({ourProps:X,theirProps:s,slot:Z,defaultTag:ft,name:"Popover.Button"}),x&&!i&&d&&E.createElement(ce,{id:u,ref:r.afterButtonSentinel,features:ve.Focusable,"data-headlessui-focus-guard":!0,as:"button",type:"button",onFocus:l}))}let vt="div",Tt=pe.RenderStrategy|pe.Static;function Oe(t,n){let P=ae(),{id:C=`headlessui-popover-backdrop-${P}`,transition:m=!1,...A}=t,[{popoverState:s},r]=se("Popover.Backdrop"),[T,d]=le(null),o=q(n,d),u=Fe(),[B,y]=_e(m,T,u!==null?(u&z.Open)===z.Open:s===0),b=g(c=>{if(xe(c.currentTarget))return c.preventDefault();r({type:1})}),i=D(()=>({open:s===0}),[s]),a={ref:o,id:C,"aria-hidden":!0,onClick:b,...Re(y)};return te({ourProps:a,theirProps:A,slot:i,defaultTag:vt,features:Tt,visible:B,name:"Popover.Backdrop"})}let mt="div",yt=pe.RenderStrategy|pe.Static;function Et(t,n){let P=ae(),{id:C=`headlessui-popover-panel-${P}`,focus:m=!1,anchor:A,portal:s=!1,modal:r=!1,transition:T=!1,...d}=t,[o,u]=se("Popover.Panel"),{close:B,isPortalled:y}=be("Popover.Panel"),b=`headlessui-focus-sentinel-before-${P}`,i=`headlessui-focus-sentinel-after-${P}`,a=ee(null),c=Ye(A),[L,_]=Xe(c),H=qe();c&&(s=!0);let[I,M]=le(null),h=q(a,n,c?L:null,g(e=>u({type:4,panel:e})),M),R=fe(a),$=rt();He(()=>(u({type:5,panelId:C}),()=>{u({type:5,panelId:null})}),[C,u]);let U=Fe(),[F,N]=_e(T,I,U!==null?(U&z.Open)===z.Open:o.popoverState===0);Ue(F,o.button,()=>{u({type:1})});let Q=o.__demoMode?!1:r&&F;je(Q,R);let x=g(e=>{var p;switch(e.key){case V.Escape:if(o.popoverState!==0||!a.current||R!=null&&R.activeElement&&!a.current.contains(R.activeElement))return;e.preventDefault(),e.stopPropagation(),u({type:1}),(p=o.button)==null||p.focus();break}});ne(()=>{var e;t.static||o.popoverState===1&&((e=t.unmount)==null||e)&&u({type:4,panel:null})},[o.popoverState,t.unmount,t.static,u]),ne(()=>{if(o.__demoMode||!m||o.popoverState!==0||!a.current)return;let e=R==null?void 0:R.activeElement;a.current.contains(e)||W(a.current,G.First)},[o.__demoMode,m,a.current,o.popoverState]);let Z=D(()=>({open:o.popoverState===0,close:B}),[o.popoverState,B]),J=ye(c?H():{},{ref:h,id:C,onKeyDown:x,onBlur:m&&o.popoverState===0?e=>{var f,v,O,S,K;let p=e.relatedTarget;p&&a.current&&((f=a.current)!=null&&f.contains(p)||(u({type:1}),((O=(v=o.beforePanelSentinel.current)==null?void 0:v.contains)!=null&&O.call(v,p)||(K=(S=o.afterPanelSentinel.current)==null?void 0:S.contains)!=null&&K.call(S,p))&&p.focus({preventScroll:!0})))}:void 0,tabIndex:-1,style:{...d.style,..._,"--button-width":ke(o.button,!0).width},...Re(N)}),X=Be(),w=g(()=>{let e=a.current;if(!e)return;function p(){j(X.current,{[k.Forwards]:()=>{var v;W(e,G.First)===Te.Error&&((v=o.afterPanelSentinel.current)==null||v.focus())},[k.Backwards]:()=>{var f;(f=o.button)==null||f.focus({preventScroll:!0})}})}p()}),l=g(()=>{let e=a.current;if(!e)return;function p(){j(X.current,{[k.Forwards]:()=>{if(!o.button)return;let f=me(),v=f.indexOf(o.button),O=f.slice(0,v+1),K=[...f.slice(v+1),...O];for(let de of K.slice())if(de.dataset.headlessuiFocusGuard==="true"||I!=null&&I.contains(de)){let Se=K.indexOf(de);Se!==-1&&K.splice(Se,1)}W(K,G.First,{sorted:!1})},[k.Backwards]:()=>{var v;W(e,G.Previous)===Te.Error&&((v=o.button)==null||v.focus())}})}p()});return E.createElement(Ze,null,E.createElement(ie.Provider,{value:C},E.createElement(ue.Provider,{value:{close:B,isPortalled:y}},E.createElement(nt,{enabled:s?t.static||F:!1},F&&y&&E.createElement(ce,{id:b,ref:o.beforePanelSentinel,features:ve.Focusable,"data-headlessui-focus-guard":!0,as:"button",type:"button",onFocus:w}),te({mergeRefs:$,ourProps:J,theirProps:d,slot:Z,defaultTag:mt,features:yt,visible:F,name:"Popover.Panel"}),F&&y&&E.createElement(ce,{id:i,ref:o.afterPanelSentinel,features:ve.Focusable,"data-headlessui-focus-guard":!0,as:"button",type:"button",onFocus:l})))))}let bt="div";function gt(t,n){let P=ee(null),C=q(P,n),[m,A]=le([]),s=g(b=>{A(i=>{let a=i.indexOf(b);if(a!==-1){let c=i.slice();return c.splice(a,1),c}return i})}),r=g(b=>(A(i=>[...i,b]),()=>s(b))),T=g(()=>{var a;let b=ot(P);if(!b)return!1;let i=b.activeElement;return(a=P.current)!=null&&a.contains(i)?!0:m.some(c=>{var L,_;return((L=b.getElementById(c.buttonId.current))==null?void 0:L.contains(i))||((_=b.getElementById(c.panelId.current))==null?void 0:_.contains(i))})}),d=g(b=>{for(let i of m)i.buttonId.current!==b&&i.close()}),o=D(()=>({registerPopover:r,unregisterPopover:s,isFocusWithinPopoverGroup:T,closeOthers:d}),[r,s,T,d]),u=D(()=>({}),[]),B=t,y={ref:C};return E.createElement(Ce,null,E.createElement(ge.Provider,{value:o},te({ourProps:y,theirProps:B,slot:u,defaultTag:bt,name:"Popover.Group"})))}let St=Y(Pt),At=Y(ct),Ct=Y(Oe),Bt=Y(Oe),Rt=Y(Et),_t=Y(gt),ao=Object.assign(St,{Button:At,Backdrop:Bt,Overlay:Ct,Panel:Rt,Group:_t});export{ao as Popover,Bt as PopoverBackdrop,At as PopoverButton,_t as PopoverGroup,Ct as PopoverOverlay,Rt as PopoverPanel}; |
{ | ||
"name": "@headlessui/react", | ||
"version": "2.1.5", | ||
"version": "2.1.6", | ||
"description": "A set of completely unstyled, fully accessible UI components for React, designed to integrate beautifully with Tailwind CSS.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.cjs", |
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
912613
16408