@headlessui/react
Advanced tools
Comparing version 0.0.0-insiders.b517a39 to 0.0.0-insiders.b670896
@@ -1,1 +0,1 @@ | ||
"use client";import{useFocusRing as y}from"@react-aria/focus";import{useHover as b}from"@react-aria/interactions";import{useMemo as P}from"react";import{useActivePress as B}from'../../hooks/use-active-press.js';import{useDisabled as c}from'../../internal/disabled.js';import{forwardRefWithAs as A,mergeProps as g,render as _}from'../../utils/render.js';let v="button";function E(a,u){var p;let l=c(),{disabled:e=l||!1,autoFocus:t=!1,...o}=a,{isFocusVisible:r,focusProps:i}=y({autoFocus:t}),{isHovered:s,hoverProps:T}=b({isDisabled:e}),{pressed:n,pressProps:f}=B({disabled:e}),m=g({ref:u,type:(p=o.type)!=null?p:"button",disabled:e||void 0,autoFocus:t},i,T,f),d=P(()=>({disabled:e,hover:s,focus:r,active:n,autofocus:t}),[e,s,r,n,t]);return _({ourProps:m,theirProps:o,slot:d,defaultTag:v,name:"Button"})}let h=A(E);export{h as Button}; | ||
"use client";import{useFocusRing as b}from"@react-aria/focus";import{useHover as P}from"@react-aria/interactions";import{useMemo as B}from"react";import{useActivePress as c}from'../../hooks/use-active-press.js';import{useDisabled as g}from'../../internal/disabled.js';import{forwardRefWithAs as A,mergeProps as _,render as F,useMergeRefsFn as R}from'../../utils/render.js';let v="button";function E(a,u){var p;let l=g(),i=R(),{disabled:e=l||!1,autoFocus:t=!1,...o}=a,{isFocusVisible:r,focusProps:T}=b({autoFocus:t}),{isHovered:s,hoverProps:f}=P({isDisabled:e}),{pressed:n,pressProps:m}=c({disabled:e}),d=_({ref:u,type:(p=o.type)!=null?p:"button",disabled:e||void 0,autoFocus:t},T,f,m),y=B(()=>({disabled:e,hover:s,focus:r,active:n,autofocus:t}),[e,s,r,n,t]);return F({mergeRefs:i,ourProps:d,theirProps:o,slot:y,defaultTag:v,name:"Button"})}let L=A(E);export{L as Button}; |
@@ -1,1 +0,1 @@ | ||
"use client";import{useFocusRing as G}from"@react-aria/focus";import{useHover as S}from"@react-aria/interactions";import n,{useCallback as W,useMemo as N,useState as w}from"react";import{useActivePress as J}from'../../hooks/use-active-press.js';import{useControllable as V}from'../../hooks/use-controllable.js';import{useDisposables as $}from'../../hooks/use-disposables.js';import{useEvent as s}from'../../hooks/use-event.js';import{useId as j}from'../../hooks/use-id.js';import{useDisabled as q}from'../../internal/disabled.js';import{FormFields as z}from'../../internal/form-fields.js';import{useProvidedId as Q}from'../../internal/id.js';import{isDisabledReactIssue7711 as Y}from'../../utils/bugs.js';import{attemptSubmit as Z}from'../../utils/form.js';import{forwardRefWithAs as ee,mergeProps as oe,render as te}from'../../utils/render.js';import{useDescribedBy as re}from'../description/description.js';import{Keys as y}from'../keyboard.js';import{useLabelledBy as ae}from'../label/label.js';let se="span";function le(T,h){let C=j(),k=Q(),x=q(),{id:g=k||`headlessui-checkbox-${C}`,disabled:o=x||!1,autoFocus:l=!1,checked:E,defaultChecked:i=!1,onChange:v,name:d,value:P,form:D,indeterminate:a=!1,...R}=T,[r,t]=V(E,v,i),A=ae(),F=re(),K=$(),[p,c]=w(!1),m=s(()=>{c(!0),t==null||t(!r),K.nextFrame(()=>{c(!1)})}),_=s(e=>{if(Y(e.currentTarget))return e.preventDefault();e.preventDefault(),m()}),H=s(e=>{e.key===y.Space?(e.preventDefault(),m()):e.key===y.Enter&&Z(e.currentTarget)}),B=s(e=>e.preventDefault()),{isFocusVisible:b,focusProps:L}=G({autoFocus:l}),{isHovered:u,hoverProps:I}=S({isDisabled:o}),{pressed:f,pressProps:M}=J({disabled:o}),U=oe({ref:h,id:g,role:"checkbox","aria-checked":a?"mixed":r?"true":"false","aria-labelledby":A,"aria-describedby":F,"aria-disabled":o?!0:void 0,indeterminate:a?"true":void 0,tabIndex:0,onKeyUp:o?void 0:H,onKeyPress:o?void 0:B,onClick:o?void 0:_},L,I,M),O=N(()=>({checked:r,disabled:o,hover:u,focus:b,active:f,indeterminate:a,changing:p,autofocus:l}),[r,a,o,u,b,f,p,l]),X=W(()=>t==null?void 0:t(i),[t]);return n.createElement(n.Fragment,null,d!=null&&n.createElement(z,{disabled:o,data:{[d]:P||"on"},overrides:{type:"checkbox",checked:r},form:D,onReset:X}),te({ourProps:U,theirProps:R,slot:O,defaultTag:se,name:"Checkbox"}))}let ve=ee(le);export{ve as Checkbox}; | ||
"use client";import{useFocusRing as S}from"@react-aria/focus";import{useHover as W}from"@react-aria/interactions";import i,{useCallback as N,useMemo as V,useState as w}from"react";import{useActivePress as J}from'../../hooks/use-active-press.js';import{useControllable as $}from'../../hooks/use-controllable.js';import{useDefaultValue as j}from'../../hooks/use-default-value.js';import{useDisposables as q}from'../../hooks/use-disposables.js';import{useEvent as l}from'../../hooks/use-event.js';import{useId as z}from'../../hooks/use-id.js';import{useDisabled as Q}from'../../internal/disabled.js';import{FormFields as Y}from'../../internal/form-fields.js';import{useProvidedId as Z}from'../../internal/id.js';import{isDisabledReactIssue7711 as ee}from'../../utils/bugs.js';import{attemptSubmit as oe}from'../../utils/form.js';import{forwardRefWithAs as te,mergeProps as re,render as ae}from'../../utils/render.js';import{useDescribedBy as ne}from'../description/description.js';import{Keys as y}from'../keyboard.js';import{useLabelledBy as le}from'../label/label.js';let se="span";function ie(T,h){let C=z(),k=Z(),x=Q(),{id:g=k||`headlessui-checkbox-${C}`,disabled:e=x||!1,autoFocus:s=!1,checked:E,defaultChecked:v,onChange:P,name:d,value:D,form:R,indeterminate:n=!1,...A}=T,r=j(v),[a,t]=$(E,P,r!=null?r:!1),F=le(),K=ne(),_=q(),[p,c]=w(!1),u=l(()=>{c(!0),t==null||t(!a),_.nextFrame(()=>{c(!1)})}),H=l(o=>{if(ee(o.currentTarget))return o.preventDefault();o.preventDefault(),u()}),B=l(o=>{o.key===y.Space?(o.preventDefault(),u()):o.key===y.Enter&&oe(o.currentTarget)}),L=l(o=>o.preventDefault()),{isFocusVisible:m,focusProps:I}=S({autoFocus:s}),{isHovered:f,hoverProps:M}=W({isDisabled:e}),{pressed:b,pressProps:U}=J({disabled:e}),O=re({ref:h,id:g,role:"checkbox","aria-checked":n?"mixed":a?"true":"false","aria-labelledby":F,"aria-describedby":K,"aria-disabled":e?!0:void 0,indeterminate:n?"true":void 0,tabIndex:e?void 0:0,onKeyUp:e?void 0:B,onKeyPress:e?void 0:L,onClick:e?void 0:H},I,M,U),X=V(()=>({checked:a,disabled:e,hover:f,focus:m,active:b,indeterminate:n,changing:p,autofocus:s}),[a,n,e,f,m,b,p,s]),G=N(()=>{if(r!==void 0)return t==null?void 0:t(r)},[t,r]);return i.createElement(i.Fragment,null,d!=null&&i.createElement(Y,{disabled:e,data:{[d]:D||"on"},overrides:{type:"checkbox",checked:a},form:R,onReset:G}),ae({ourProps:O,theirProps:A,slot:X,defaultTag:se,name:"Checkbox"}))}let Re=te(ie);export{Re as Checkbox}; |
@@ -30,5 +30,6 @@ import React, { type ElementType, type Ref } from 'react'; | ||
virtual?: { | ||
options: NoInfer<TValue>[]; | ||
disabled?: (value: NoInfer<TValue>) => boolean; | ||
options: TMultiple extends true ? EnsureArray<NoInfer<TValue>> : NoInfer<TValue>[]; | ||
disabled?: (value: TMultiple extends true ? EnsureArray<NoInfer<TValue>>[number] : NoInfer<TValue>) => boolean; | ||
} | null; | ||
onClose?(): void; | ||
__demoMode?: boolean; | ||
@@ -72,3 +73,3 @@ }>; | ||
open: boolean; | ||
option: unknown; | ||
option: any; | ||
}; | ||
@@ -80,4 +81,7 @@ type OptionsPropsWeControl = 'aria-labelledby' | 'aria-multiselectable' | 'role' | 'tabIndex'; | ||
anchor?: AnchorProps; | ||
portal?: boolean; | ||
modal?: boolean; | ||
transition?: boolean; | ||
}>; | ||
declare function OptionsFn<TTag extends ElementType = typeof DEFAULT_OPTIONS_TAG>(props: ComboboxOptionsProps<TTag>, ref: Ref<HTMLUListElement>): React.ReactElement<any, string | React.JSXElementConstructor<any>> | null; | ||
declare function OptionsFn<TTag extends ElementType = typeof DEFAULT_OPTIONS_TAG>(props: ComboboxOptionsProps<TTag>, ref: Ref<HTMLElement>): React.JSX.Element; | ||
declare let DEFAULT_OPTION_TAG: "div"; | ||
@@ -97,3 +101,3 @@ type OptionRenderPropArg = { | ||
}>; | ||
declare function OptionFn<TTag extends ElementType = typeof DEFAULT_OPTION_TAG, TType = Parameters<typeof ComboboxRoot>[0]['value']>(props: ComboboxOptionProps<TTag, TType>, ref: Ref<HTMLLIElement>): React.ReactElement<any, string | React.JSXElementConstructor<any>> | null; | ||
declare function OptionFn<TTag extends ElementType = typeof DEFAULT_OPTION_TAG, TType = Parameters<typeof ComboboxRoot>[0]['value']>(props: ComboboxOptionProps<TTag, TType>, ref: Ref<HTMLElement>): React.ReactElement<any, string | React.JSXElementConstructor<any>> | null; | ||
export interface _internal_ComponentCombobox extends HasDisplayName { | ||
@@ -124,9 +128,13 @@ <TValue, TMultiple extends boolean | undefined = false, TTag extends ElementType = typeof DEFAULT_COMBOBOX_TAG>(props: ComboboxProps<TValue, TMultiple, TTag> & RefProp<typeof ComboboxFn>): JSX.Element; | ||
export declare let Combobox: _internal_ComponentCombobox & { | ||
/** @deprecated use `<ComboboxInput>` instead of `<Combobox.Input>` */ | ||
Input: _internal_ComponentComboboxInput; | ||
/** @deprecated use `<ComboboxButton>` instead of `<Combobox.Button>` */ | ||
Button: _internal_ComponentComboboxButton; | ||
/** @deprecated use `<Label>` instead of `<Combobox.Label>` */ | ||
Label: _internal_ComponentComboboxLabel; | ||
/** @deprecated use `<ComboboxOptions>` instead of `<Combobox.Options>` */ | ||
Options: _internal_ComponentComboboxOptions; | ||
/** @deprecated use `<ComboboxOption>` instead of `<Combobox.Option>` */ | ||
Option: _internal_ComponentComboboxOption; | ||
}; | ||
export {}; |
@@ -1,1 +0,1 @@ | ||
"use client";import{useFocusRing as ge}from"@react-aria/focus";import{useHover as ve}from"@react-aria/interactions";import{useVirtualizer as he}from"@tanstack/react-virtual";import V,{Fragment as Oe,createContext as se,createRef as Me,useCallback as Ce,useContext as de,useMemo as k,useReducer as Ve,useRef as H,useState as Le}from"react";import{useActivePress as we}from'../../hooks/use-active-press.js';import{useByComparator as Be}from'../../hooks/use-by-comparator.js';import{useControllable as Ue}from'../../hooks/use-controllable.js';import{useDisposables as ye}from'../../hooks/use-disposables.js';import{useElementSize as Re}from'../../hooks/use-element-size.js';import{useEvent as v}from'../../hooks/use-event.js';import{useFrameDebounce as Ne}from'../../hooks/use-frame-debounce.js';import{useId as re}from'../../hooks/use-id.js';import{useIsoMorphicEffect as j}from'../../hooks/use-iso-morphic-effect.js';import{useLatestValue as ke}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 je}from'../../hooks/use-owner.js';import{useRefocusableInput as Se}from'../../hooks/use-refocusable-input.js';import{useResolveButtonType as Ke}from'../../hooks/use-resolve-button-type.js';import{useSyncRefs as ie}from'../../hooks/use-sync-refs.js';import{useTrackedPointer as We}from'../../hooks/use-tracked-pointer.js';import{useTreeWalker as ze}from'../../hooks/use-tree-walker.js';import{useWatch as Pe}from'../../hooks/use-watch.js';import{useDisabled as $e}from'../../internal/disabled.js';import{FloatingProvider as Xe,useFloatingPanel as Je,useFloatingPanelProps as qe,useFloatingReference as Ye}from'../../internal/floating.js';import{FormFields as Qe}from'../../internal/form-fields.js';import{useProvidedId as Ze}from'../../internal/id.js';import{OpenClosedProvider as eo,State as ae,useOpenClosed as oo}from'../../internal/open-closed.js';import{history as Ie}from'../../utils/active-element-history.js';import{isDisabledReactIssue7711 as to}from'../../utils/bugs.js';import{Focus as I,calculateActiveIndex as Ae}from'../../utils/calculate-active-index.js';import{disposables as Ee}from'../../utils/disposables.js';import{sortByDomNode as no}from'../../utils/focus-management.js';import{match as $}from'../../utils/match.js';import{isMobile as ro}from'../../utils/platform.js';import{RenderFeatures as Fe,forwardRefWithAs as q,mergeProps as be,render as Y}from'../../utils/render.js';import{useDescribedBy as io}from'../description/description.js';import{Keys as D}from'../keyboard.js';import{Label as ao,useLabelledBy as ce,useLabels as lo}from'../label/label.js';import{MouseButton as _e}from'../mouse.js';var uo=(e=>(e[e.Open=0]="Open",e[e.Closed=1]="Closed",e))(uo||{}),po=(e=>(e[e.Single=0]="Single",e[e.Multi=1]="Multi",e))(po||{}),so=(t=>(t[t.Pointer=0]="Pointer",t[t.Focus=1]="Focus",t[t.Other=2]="Other",t))(so||{}),bo=(i=>(i[i.OpenCombobox=0]="OpenCombobox",i[i.CloseCombobox=1]="CloseCombobox",i[i.GoToOption=2]="GoToOption",i[i.RegisterOption=3]="RegisterOption",i[i.UnregisterOption=4]="UnregisterOption",i[i.SetActivationTrigger=5]="SetActivationTrigger",i[i.UpdateVirtualOptions=6]="UpdateVirtualOptions",i))(bo||{});function fe(o,r=e=>e){let e=o.activeOptionIndex!==null?o.options[o.activeOptionIndex]:null,t=r(o.options.slice()),l=t.length>0&&t[0].dataRef.current.order!==null?t.sort((m,i)=>m.dataRef.current.order-i.dataRef.current.order):no(t,m=>m.dataRef.current.domRef.current),d=e?l.indexOf(e):null;return d===-1&&(d=null),{options:l,activeOptionIndex:d}}let co={[1](o){var r;return(r=o.dataRef.current)!=null&&r.disabled||o.comboboxState===1?o:{...o,activeOptionIndex:null,comboboxState:1}},[0](o){var r,e;if((r=o.dataRef.current)!=null&&r.disabled||o.comboboxState===0)return o;if((e=o.dataRef.current)!=null&&e.value){let t=o.dataRef.current.calculateIndex(o.dataRef.current.value);if(t!==-1)return{...o,activeOptionIndex:t,comboboxState:0}}return{...o,comboboxState:0}},[2](o,r){var d,m,i,n,b;if((d=o.dataRef.current)!=null&&d.disabled||(m=o.dataRef.current)!=null&&m.optionsRef.current&&!((i=o.dataRef.current)!=null&&i.optionsPropsRef.current.static)&&o.comboboxState===1)return o;if(o.virtual){let f=r.focus===I.Specific?r.idx:Ae(r,{resolveItems:()=>o.virtual.options,resolveActiveIndex:()=>{var F,s;return(s=(F=o.activeOptionIndex)!=null?F:o.virtual.options.findIndex(E=>!o.virtual.disabled(E)))!=null?s:null},resolveDisabled:o.virtual.disabled,resolveId(){throw new Error("Function not implemented.")}}),x=(n=r.trigger)!=null?n:2;return o.activeOptionIndex===f&&o.activationTrigger===x?o:{...o,activeOptionIndex:f,activationTrigger:x}}let e=fe(o);if(e.activeOptionIndex===null){let f=e.options.findIndex(x=>!x.dataRef.current.disabled);f!==-1&&(e.activeOptionIndex=f)}let t=r.focus===I.Specific?r.idx:Ae(r,{resolveItems:()=>e.options,resolveActiveIndex:()=>e.activeOptionIndex,resolveId:f=>f.id,resolveDisabled:f=>f.dataRef.current.disabled}),l=(b=r.trigger)!=null?b:2;return o.activeOptionIndex===t&&o.activationTrigger===l?o:{...o,...e,activeOptionIndex:t,activationTrigger:l}},[3]:(o,r)=>{var d,m,i;if((d=o.dataRef.current)!=null&&d.virtual)return{...o,options:[...o.options,r.payload]};let e=r.payload,t=fe(o,n=>(n.push(e),n));o.activeOptionIndex===null&&(m=o.dataRef.current)!=null&&m.isSelected(r.payload.dataRef.current.value)&&(t.activeOptionIndex=t.options.indexOf(e));let l={...o,...t,activationTrigger:2};return(i=o.dataRef.current)!=null&&i.__demoMode&&o.dataRef.current.value===void 0&&(l.activeOptionIndex=0),l},[4]:(o,r)=>{var t;if((t=o.dataRef.current)!=null&&t.virtual)return{...o,options:o.options.filter(l=>l.id!==r.id)};let e=fe(o,l=>{let d=l.findIndex(m=>m.id===r.id);return d!==-1&&l.splice(d,1),l});return{...o,...e,activationTrigger:2}},[5]:(o,r)=>o.activationTrigger===r.trigger?o:{...o,activationTrigger:r.trigger},[6]:(o,r)=>{var t;if(((t=o.virtual)==null?void 0:t.options)===r.options)return o;let e=o.activeOptionIndex;if(o.activeOptionIndex!==null){let l=r.options.indexOf(o.virtual.options[o.activeOptionIndex]);l!==-1?e=l:e=null}return{...o,activeOptionIndex:e,virtual:Object.assign({},o.virtual,{options:r.options})}}},me=se(null);me.displayName="ComboboxActionsContext";function Q(o){let r=de(me);if(r===null){let e=new Error(`<${o} /> is missing a parent <Combobox /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(e,Q),e}return r}let De=se(null);function fo(o){var i;let r=X("VirtualProvider"),[e,t]=k(()=>{let n=r.optionsRef.current;if(!n)return[0,0];let b=window.getComputedStyle(n);return[parseFloat(b.paddingBlockStart||b.paddingTop),parseFloat(b.paddingBlockEnd||b.paddingBottom)]},[r.optionsRef.current]),l=he({scrollPaddingStart:e,scrollPaddingEnd:t,count:r.virtual.options.length,estimateSize(){return 40},getScrollElement(){var n;return(n=r.optionsRef.current)!=null?n:null},overscan:12}),[d,m]=Le(0);return j(()=>{m(n=>n+1)},[(i=r.virtual)==null?void 0:i.options]),V.createElement(De.Provider,{value:l},V.createElement("div",{style:{position:"relative",width:"100%",height:`${l.getTotalSize()}px`},ref:n=>{if(n){if(typeof process!="undefined"&&process.env.JEST_WORKER_ID!==void 0||r.activationTrigger===0)return;r.activeOptionIndex!==null&&r.virtual.options.length>r.activeOptionIndex&&l.scrollToIndex(r.activeOptionIndex)}}},l.getVirtualItems().map(n=>{var b;return V.createElement(Oe,{key:n.key},V.cloneElement((b=o.children)==null?void 0:b.call(o,{option:r.virtual.options[n.index],open:r.comboboxState===0}),{key:`${d}-${n.key}`,"data-index":n.index,"aria-setsize":r.virtual.options.length,"aria-posinset":n.index+1,style:{position:"absolute",top:0,left:0,transform:`translateY(${n.start}px)`,overflowAnchor:"none"}}))})))}let xe=se(null);xe.displayName="ComboboxDataContext";function X(o){let r=de(xe);if(r===null){let e=new Error(`<${o} /> is missing a parent <Combobox /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(e,X),e}return r}function mo(o,r){return $(r.type,co,o,r)}let xo=Oe;function To(o,r){var h,C;let e=$e(),{value:t,defaultValue:l,onChange:d,form:m,name:i,by:n,disabled:b=e||!1,__demoMode:f=!1,multiple:x=!1,immediate:F=!1,virtual:s=null,nullable:E,...T}=o,[P=x?[]:void 0,O]=Ue(t,d,l),[y,g]=Ve(mo,{dataRef:Me(),comboboxState:f?0:1,options:[],virtual:s?{options:s.options,disabled:(h=s.disabled)!=null?h:()=>!1}:null,activeOptionIndex:null,activationTrigger:2}),M=H(!1),B=H({static:!1,hold:!1}),G=H(null),U=H(null),R=H(null),L=Be(n),J=v(p=>s?n===null?s.options.indexOf(p):s.options.findIndex(c=>L(c,p)):y.options.findIndex(c=>L(c.dataRef.current.value,p))),K=Ce(p=>$(a.mode,{[1]:()=>P.some(c=>L(c,p)),[0]:()=>L(P,p)}),[P]),S=v(p=>y.activeOptionIndex===J(p)),a=k(()=>({...y,immediate:F,optionsPropsRef:B,inputRef:G,buttonRef:U,optionsRef:R,value:P,defaultValue:l,disabled:b,mode:x?1:0,virtual:y.virtual,get activeOptionIndex(){if(M.current&&y.activeOptionIndex===null&&(s?s.options.length>0:y.options.length>0)){if(s){let c=s.options.findIndex(w=>{var ne,Te;return!((Te=(ne=s==null?void 0:s.disabled)==null?void 0:ne.call(s,w))!=null&&Te)});if(c!==-1)return c}let p=y.options.findIndex(c=>!c.dataRef.current.disabled);if(p!==-1)return p}return y.activeOptionIndex},calculateIndex:J,compare:L,isSelected:K,isActive:S,__demoMode:f}),[P,l,b,x,f,y,s]);j(()=>{s&&g({type:6,options:s.options})},[s,s==null?void 0:s.options]),j(()=>{y.dataRef.current=a},[a]),Ge([a.buttonRef,a.inputRef,a.optionsRef],()=>z.closeCombobox(),a.comboboxState===0);let N=k(()=>{var p,c,w;return{open:a.comboboxState===0,disabled:b,activeIndex:a.activeOptionIndex,activeOption:a.activeOptionIndex===null?null:a.virtual?a.virtual.options[(p=a.activeOptionIndex)!=null?p:0]:(w=(c=a.options[a.activeOptionIndex])==null?void 0:c.dataRef.current.value)!=null?w:null,value:P}},[a,b,P]),Z=v(()=>{if(a.activeOptionIndex!==null){if(a.virtual)W(a.virtual.options[a.activeOptionIndex]);else{let{dataRef:p}=a.options[a.activeOptionIndex];W(p.current.value)}z.goToOption(I.Specific,a.activeOptionIndex)}}),le=v(()=>{g({type:0}),M.current=!0}),ue=v(()=>{g({type:1}),M.current=!1}),pe=v((p,c,w)=>(M.current=!1,p===I.Specific?g({type:2,focus:I.Specific,idx:c,trigger:w}):g({type:2,focus:p,trigger:w}))),ee=v((p,c)=>(g({type:3,payload:{id:p,dataRef:c}}),()=>{a.isActive(c.current.value)&&(M.current=!0),g({type:4,id:p})})),W=v(p=>$(a.mode,{[0](){return O==null?void 0:O(p)},[1](){let c=a.value.slice(),w=c.findIndex(ne=>L(ne,p));return w===-1?c.push(p):c.splice(w,1),O==null?void 0:O(c)}})),oe=v(p=>{g({type:5,trigger:p})}),z=k(()=>({onChange:W,registerOption:ee,goToOption:pe,closeCombobox:ue,openCombobox:le,setActivationTrigger:oe,selectActiveOption:Z}),[]),[te,u]=lo(),_=r===null?{}:{ref:r},A=Ce(()=>O==null?void 0:O(l),[O]);return V.createElement(u,{value:te,props:{htmlFor:(C=a.inputRef.current)==null?void 0:C.id},slot:{open:a.comboboxState===0,disabled:b}},V.createElement(Xe,null,V.createElement(me.Provider,{value:z},V.createElement(xe.Provider,{value:a},V.createElement(eo,{value:$(a.comboboxState,{[0]:ae.Open,[1]:ae.Closed})},i!=null&&V.createElement(Qe,{disabled:b,data:P!=null?{[i]:P}:{},form:m,onReset:A}),Y({ourProps:_,theirProps:T,slot:N,defaultTag:xo,name:"Combobox"}))))))}let go="input";function vo(o,r){var ee,W,oe,z,te;let e=X("Combobox.Input"),t=Q("Combobox.Input"),l=re(),d=Ze(),{id:m=d||`headlessui-combobox-input-${l}`,onChange:i,displayValue:n,disabled:b=e.disabled||!1,autoFocus:f=!1,type:x="text",...F}=o,s=ie(e.inputRef,r,Ye()),E=je(e.inputRef),T=H(!1),P=ye(),O=v(()=>{t.onChange(null),e.optionsRef.current&&(e.optionsRef.current.scrollTop=0),t.goToOption(I.Nothing)}),y=k(()=>{var u;return typeof n=="function"&&e.value!==void 0?(u=n(e.value))!=null?u:"":typeof e.value=="string"?e.value:""},[e.value,n]);Pe(([u,_],[A,h])=>{if(T.current)return;let C=e.inputRef.current;C&&((h===0&&_===1||u!==A)&&(C.value=u),requestAnimationFrame(()=>{if(T.current||!C||(E==null?void 0:E.activeElement)!==C)return;let{selectionStart:p,selectionEnd:c}=C;Math.abs((c!=null?c:0)-(p!=null?p:0))===0&&p===0&&C.setSelectionRange(C.value.length,C.value.length)}))},[y,e.comboboxState,E]),Pe(([u],[_])=>{if(u===0&&_===1){if(T.current)return;let A=e.inputRef.current;if(!A)return;let h=A.value,{selectionStart:C,selectionEnd:p,selectionDirection:c}=A;A.value="",A.value=h,c!==null?A.setSelectionRange(C,p,c):A.setSelectionRange(C,p)}},[e.comboboxState]);let g=H(!1),M=v(()=>{g.current=!0}),B=v(()=>{P.nextFrame(()=>{g.current=!1})}),G=Ne(),U=v(u=>{switch(T.current=!0,G(()=>{T.current=!1}),u.key){case D.Enter:if(T.current=!1,e.comboboxState!==0||g.current)return;if(u.preventDefault(),u.stopPropagation(),e.activeOptionIndex===null){t.closeCombobox();return}t.selectActiveOption(),e.mode===0&&t.closeCombobox();break;case D.ArrowDown:return T.current=!1,u.preventDefault(),u.stopPropagation(),$(e.comboboxState,{[0]:()=>t.goToOption(I.Next),[1]:()=>t.openCombobox()});case D.ArrowUp:return T.current=!1,u.preventDefault(),u.stopPropagation(),$(e.comboboxState,{[0]:()=>t.goToOption(I.Previous),[1]:()=>{t.openCombobox(),P.nextFrame(()=>{e.value||t.goToOption(I.Last)})}});case D.Home:if(u.shiftKey)break;return T.current=!1,u.preventDefault(),u.stopPropagation(),t.goToOption(I.First);case D.PageUp:return T.current=!1,u.preventDefault(),u.stopPropagation(),t.goToOption(I.First);case D.End:if(u.shiftKey)break;return T.current=!1,u.preventDefault(),u.stopPropagation(),t.goToOption(I.Last);case D.PageDown:return T.current=!1,u.preventDefault(),u.stopPropagation(),t.goToOption(I.Last);case D.Escape:return T.current=!1,e.comboboxState!==0?void 0:(u.preventDefault(),e.optionsRef.current&&!e.optionsPropsRef.current.static&&u.stopPropagation(),e.mode===0&&e.value===null&&O(),t.closeCombobox());case D.Tab:if(T.current=!1,e.comboboxState!==0)return;e.mode===0&&e.activationTrigger!==1&&t.selectActiveOption(),t.closeCombobox();break}}),R=v(u=>{i==null||i(u),e.mode===0&&u.target.value===""&&O(),t.openCombobox()}),L=v(u=>{var A,h,C;let _=(A=u.relatedTarget)!=null?A:Ie.find(p=>p!==u.currentTarget);if(T.current=!1,!((h=e.optionsRef.current)!=null&&h.contains(_))&&!((C=e.buttonRef.current)!=null&&C.contains(_))&&e.comboboxState===0)return u.preventDefault(),e.mode===0&&e.value===null&&O(),t.closeCombobox()}),J=v(u=>{var A,h,C;let _=(A=u.relatedTarget)!=null?A:Ie.find(p=>p!==u.currentTarget);(h=e.buttonRef.current)!=null&&h.contains(_)||(C=e.optionsRef.current)!=null&&C.contains(_)||e.disabled||e.immediate&&e.comboboxState!==0&&(t.openCombobox(),P.nextFrame(()=>{t.setActivationTrigger(1)}))}),K=ce(),S=io(),{isFocused:a,focusProps:N}=ge({autoFocus:f}),{isHovered:Z,hoverProps:le}=ve({isDisabled:b}),ue=k(()=>({open:e.comboboxState===0,disabled:b,hover:Z,focus:a,autofocus:f}),[e,Z,a,f,b]),pe=be({ref:s,id:m,role:"combobox",type:x,"aria-controls":(ee=e.optionsRef.current)==null?void 0:ee.id,"aria-expanded":e.comboboxState===0,"aria-activedescendant":e.activeOptionIndex===null?void 0:e.virtual?(W=e.options.find(u=>{var _;return!((_=e.virtual)!=null&&_.disabled(u.dataRef.current.value))&&e.compare(u.dataRef.current.value,e.virtual.options[e.activeOptionIndex])}))==null?void 0:W.id:(oe=e.options[e.activeOptionIndex])==null?void 0:oe.id,"aria-labelledby":K,"aria-describedby":S,"aria-autocomplete":"list",defaultValue:(te=(z=o.defaultValue)!=null?z:e.defaultValue!==void 0?n==null?void 0:n(e.defaultValue):null)!=null?te:e.defaultValue,disabled:b||void 0,autoFocus:f,onCompositionStart:M,onCompositionEnd:B,onKeyDown:U,onChange:R,onFocus:J,onBlur:L},N,le);return Y({ourProps:pe,theirProps:F,slot:ue,defaultTag:go,name:"Combobox.Input"})}let Oo="button";function Co(o,r){var U;let e=X("Combobox.Button"),t=Q("Combobox.Button"),l=ie(e.buttonRef,r),d=re(),{id:m=`headlessui-combobox-button-${d}`,disabled:i=e.disabled||!1,autoFocus:n=!1,...b}=o,f=ye(),x=Se(e.inputRef),F=v(R=>{switch(R.key){case D.Space:case D.Enter:return R.preventDefault(),R.stopPropagation(),e.comboboxState===1&&t.openCombobox(),f.nextFrame(()=>x());case D.ArrowDown:return R.preventDefault(),R.stopPropagation(),e.comboboxState===1&&(t.openCombobox(),f.nextFrame(()=>{e.value||t.goToOption(I.First)})),f.nextFrame(()=>x());case D.ArrowUp:return R.preventDefault(),R.stopPropagation(),e.comboboxState===1&&(t.openCombobox(),f.nextFrame(()=>{e.value||t.goToOption(I.Last)})),f.nextFrame(()=>x());case D.Escape:return e.comboboxState!==0?void 0:(R.preventDefault(),e.optionsRef.current&&!e.optionsPropsRef.current.static&&R.stopPropagation(),t.closeCombobox(),f.nextFrame(()=>x()));default:return}}),s=v(R=>{R.preventDefault(),!to(R.currentTarget)&&(R.button===_e.Left&&(e.comboboxState===0?t.closeCombobox():t.openCombobox()),x())}),E=ce([m]),{isFocusVisible:T,focusProps:P}=ge({autoFocus:n}),{isHovered:O,hoverProps:y}=ve({isDisabled:i}),{pressed:g,pressProps:M}=we({disabled:i}),B=k(()=>({open:e.comboboxState===0,active:g||e.comboboxState===0,disabled:i,value:e.value,hover:O,focus:T}),[e,O,T,g,i]),G=be({ref:l,id:m,type:Ke(o,e.buttonRef),tabIndex:-1,"aria-haspopup":"listbox","aria-controls":(U=e.optionsRef.current)==null?void 0:U.id,"aria-expanded":e.comboboxState===0,"aria-labelledby":E,disabled:i||void 0,autoFocus:n,onMouseDown:s,onKeyDown:F},P,y,M);return Y({ourProps:G,theirProps:b,slot:B,defaultTag:Oo,name:"Combobox.Button"})}let yo="div",Ro=Fe.RenderStrategy|Fe.Static;function So(o,r){var y;let e=re(),{id:t=`headlessui-combobox-options-${e}`,hold:l=!1,anchor:d,...m}=o,i=X("Combobox.Options"),n=Q("Combobox.Options"),[b,f]=Je(d),x=qe(),F=ie(i.optionsRef,r,d?b:null),s=oo(),E=(()=>s!==null?(s&ae.Open)===ae.Open:i.comboboxState===0)();He(i.inputRef,n.closeCombobox,E),j(()=>{var g;i.optionsPropsRef.current.static=(g=o.static)!=null?g:!1},[i.optionsPropsRef,o.static]),j(()=>{i.optionsPropsRef.current.hold=l},[i.optionsPropsRef,l]),ze({container:i.optionsRef.current,enabled:i.comboboxState===0,accept(g){return g.getAttribute("role")==="option"?NodeFilter.FILTER_REJECT:g.hasAttribute("role")?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT},walk(g){g.setAttribute("role","none")}});let T=ce([(y=i.buttonRef.current)==null?void 0:y.id]),P=k(()=>({open:i.comboboxState===0,option:void 0}),[i]),O=be(d?x():{},{"aria-labelledby":T,role:"listbox","aria-multiselectable":i.mode===1?!0:void 0,id:t,ref:F,style:{...f,"--input-width":Re(i.inputRef,!0).width,"--button-width":Re(i.buttonRef,!0).width}});return i.virtual&&i.comboboxState===0&&Object.assign(m,{children:V.createElement(fo,null,m.children)}),Y({ourProps:O,theirProps:m,slot:P,defaultTag:yo,features:Ro,visible:E,name:"Combobox.Options"})}let Po="div";function Io(o,r){var K;let e=re(),{id:t=`headlessui-combobox-option-${e}`,disabled:l=!1,value:d,order:m=null,...i}=o,n=X("Combobox.Option"),b=Q("Combobox.Option"),f=Se(n.inputRef),x=n.virtual?n.activeOptionIndex===n.calculateIndex(d):n.activeOptionIndex===null?!1:((K=n.options[n.activeOptionIndex])==null?void 0:K.id)===t,F=n.isSelected(d),s=H(null),E=ke({disabled:l,value:d,domRef:s,order:m}),T=de(De),P=ie(r,s,T?T.measureElement:null),O=v(()=>b.onChange(d));j(()=>b.registerOption(t,E),[E,t]);let y=H(!(n.virtual||n.__demoMode));j(()=>{if(!n.virtual||!n.__demoMode)return;let S=Ee();return S.requestAnimationFrame(()=>{y.current=!0}),S.dispose},[n.virtual,n.__demoMode]),j(()=>{if(!y.current||n.comboboxState!==0||!x||n.activationTrigger===0)return;let S=Ee();return S.requestAnimationFrame(()=>{var a,N;(N=(a=s.current)==null?void 0:a.scrollIntoView)==null||N.call(a,{block:"nearest"})}),S.dispose},[s,x,n.comboboxState,n.activationTrigger,n.activeOptionIndex]);let g=v(S=>{var a;S.preventDefault(),S.button===_e.Left&&(l||(a=n.virtual)!=null&&a.disabled(d)||(O(),ro()||requestAnimationFrame(()=>f()),n.mode===0&&requestAnimationFrame(()=>b.closeCombobox())))}),M=v(()=>{var a;if(l||(a=n.virtual)!=null&&a.disabled(d))return b.goToOption(I.Nothing);let S=n.calculateIndex(d);b.goToOption(I.Specific,S)}),B=We(),G=v(S=>B.update(S)),U=v(S=>{var N;if(!B.wasMoved(S)||l||(N=n.virtual)!=null&&N.disabled(d)||x)return;let a=n.calculateIndex(d);b.goToOption(I.Specific,a,0)}),R=v(S=>{var a;B.wasMoved(S)&&(l||(a=n.virtual)!=null&&a.disabled(d)||x&&(n.optionsPropsRef.current.hold||b.goToOption(I.Nothing)))}),L=k(()=>({active:x,focus:x,selected:F,disabled:l}),[x,F,l]);return Y({ourProps:{id:t,ref:P,role:"option",tabIndex:l===!0?void 0:-1,"aria-disabled":l===!0?!0:void 0,"aria-selected":F,disabled:void 0,onMouseDown:g,onFocus:M,onPointerEnter:G,onMouseEnter:G,onPointerMove:U,onMouseMove:U,onPointerLeave:R,onMouseLeave:R},theirProps:i,slot:L,defaultTag:Po,name:"Combobox.Option"})}let Ao=q(To),Eo=q(Co),Fo=q(vo),_o=ao,Do=q(So),ho=q(Io),Ot=Object.assign(Ao,{Input:Fo,Button:Eo,Label:_o,Options:Do,Option:ho});export{Ot as Combobox,Eo as ComboboxButton,Fo as ComboboxInput,_o as ComboboxLabel,ho as ComboboxOption,Do as ComboboxOptions}; | ||
"use client";import{useFocusRing as Ee}from"@react-aria/focus";import{useHover as Se}from"@react-aria/interactions";import{useVirtualizer as ke}from"@tanstack/react-virtual";import D,{Fragment as Ie,createContext as me,createRef as He,useCallback as ce,useContext as fe,useMemo as K,useReducer as Ue,useRef as Z,useState as Pe}from"react";import{flushSync as ee}from"react-dom";import{useActivePress as Ge}from'../../hooks/use-active-press.js';import{useByComparator as ze}from'../../hooks/use-by-comparator.js';import{useControllable as Ke}from'../../hooks/use-controllable.js';import{useDefaultValue as We}from'../../hooks/use-default-value.js';import{useDisposables as je}from'../../hooks/use-disposables.js';import{useElementSize as Ae}from'../../hooks/use-element-size.js';import{useEvent as m}from'../../hooks/use-event.js';import{useId as se}from'../../hooks/use-id.js';import{useInertOthers as $e}from'../../hooks/use-inert-others.js';import{useIsoMorphicEffect as J}from'../../hooks/use-iso-morphic-effect.js';import{useLatestValue as Xe}from'../../hooks/use-latest-value.js';import{useOnDisappear as Je}from'../../hooks/use-on-disappear.js';import{useOutsideClick as qe}from'../../hooks/use-outside-click.js';import{useOwnerDocument as Re}from'../../hooks/use-owner.js';import{useRefocusableInput as _e}from'../../hooks/use-refocusable-input.js';import{useResolveButtonType as Ye}from'../../hooks/use-resolve-button-type.js';import{useScrollLock as Qe}from'../../hooks/use-scroll-lock.js';import{useSyncRefs as de}from'../../hooks/use-sync-refs.js';import{useTrackedPointer as Ze}from'../../hooks/use-tracked-pointer.js';import{transitionDataAttributes as et,useTransition as tt}from'../../hooks/use-transition.js';import{useTreeWalker as ot}from'../../hooks/use-tree-walker.js';import{useWatch as he}from'../../hooks/use-watch.js';import{useDisabled as nt}from'../../internal/disabled.js';import{FloatingProvider as it,useFloatingPanel as rt,useFloatingPanelProps as lt,useFloatingReference as at,useResolvedAnchor as ut}from'../../internal/floating.js';import{FormFields as pt}from'../../internal/form-fields.js';import{Frozen as st,useFrozenData as Me}from'../../internal/frozen.js';import{useProvidedId as dt}from'../../internal/id.js';import{OpenClosedProvider as bt,State as be,useOpenClosed as mt}from'../../internal/open-closed.js';import{history as De}from'../../utils/active-element-history.js';import{isDisabledReactIssue7711 as ct}from'../../utils/bugs.js';import{Focus as I,calculateActiveIndex as Fe}from'../../utils/calculate-active-index.js';import{disposables as Ve}from'../../utils/disposables.js';import{sortByDomNode as ft}from'../../utils/focus-management.js';import{match as te}from'../../utils/match.js';import{isMobile as Tt}from'../../utils/platform.js';import{RenderFeatures as Le,forwardRefWithAs as ie,mergeProps as Te,render as re,useMergeRefsFn as xt}from'../../utils/render.js';import{useDescribedBy as gt}from'../description/description.js';import{Keys as L}from'../keyboard.js';import{Label as vt,useLabelledBy as xe,useLabels as yt}from'../label/label.js';import{MouseButton as Be}from'../mouse.js';import{Portal as Ot}from'../portal/portal.js';var Ct=(e=>(e[e.Open=0]="Open",e[e.Closed=1]="Closed",e))(Ct||{}),Et=(e=>(e[e.Single=0]="Single",e[e.Multi=1]="Multi",e))(Et||{}),St=(o=>(o[o.Pointer=0]="Pointer",o[o.Focus=1]="Focus",o[o.Other=2]="Other",o))(St||{}),It=(l=>(l[l.OpenCombobox=0]="OpenCombobox",l[l.CloseCombobox=1]="CloseCombobox",l[l.GoToOption=2]="GoToOption",l[l.SetTyping=3]="SetTyping",l[l.RegisterOption=4]="RegisterOption",l[l.UnregisterOption=5]="UnregisterOption",l[l.SetActivationTrigger=6]="SetActivationTrigger",l[l.UpdateVirtualConfiguration=7]="UpdateVirtualConfiguration",l[l.SetInputElement=8]="SetInputElement",l[l.SetButtonElement=9]="SetButtonElement",l[l.SetOptionsElement=10]="SetOptionsElement",l))(It||{});function ge(t,n=e=>e){let e=t.activeOptionIndex!==null?t.options[t.activeOptionIndex]:null,o=n(t.options.slice()),c=o.length>0&&o[0].dataRef.current.order!==null?o.sort((f,b)=>f.dataRef.current.order-b.dataRef.current.order):ft(o,f=>f.dataRef.current.domRef.current),d=e?c.indexOf(e):null;return d===-1&&(d=null),{options:c,activeOptionIndex:d}}let Pt={[1](t){var n;return(n=t.dataRef.current)!=null&&n.disabled||t.comboboxState===1?t:{...t,activeOptionIndex:null,comboboxState:1,isTyping:!1,activationTrigger:2,__demoMode:!1}},[0](t){var n,e;if((n=t.dataRef.current)!=null&&n.disabled||t.comboboxState===0)return t;if((e=t.dataRef.current)!=null&&e.value){let o=t.dataRef.current.calculateIndex(t.dataRef.current.value);if(o!==-1)return{...t,activeOptionIndex:o,comboboxState:0,__demoMode:!1}}return{...t,comboboxState:0,__demoMode:!1}},[3](t,n){return t.isTyping===n.isTyping?t:{...t,isTyping:n.isTyping}},[2](t,n){var d,f,b,T;if((d=t.dataRef.current)!=null&&d.disabled||t.optionsElement&&!((f=t.dataRef.current)!=null&&f.optionsPropsRef.current.static)&&t.comboboxState===1)return t;if(t.virtual){let{options:r,disabled:i}=t.virtual,l=n.focus===I.Specific?n.idx:Fe(n,{resolveItems:()=>r,resolveActiveIndex:()=>{var R,s;return(s=(R=t.activeOptionIndex)!=null?R:r.findIndex(M=>!i(M)))!=null?s:null},resolveDisabled:i,resolveId(){throw new Error("Function not implemented.")}}),E=(b=n.trigger)!=null?b:2;return t.activeOptionIndex===l&&t.activationTrigger===E?t:{...t,activeOptionIndex:l,activationTrigger:E,isTyping:!1,__demoMode:!1}}let e=ge(t);if(e.activeOptionIndex===null){let r=e.options.findIndex(i=>!i.dataRef.current.disabled);r!==-1&&(e.activeOptionIndex=r)}let o=n.focus===I.Specific?n.idx:Fe(n,{resolveItems:()=>e.options,resolveActiveIndex:()=>e.activeOptionIndex,resolveId:r=>r.id,resolveDisabled:r=>r.dataRef.current.disabled}),c=(T=n.trigger)!=null?T:2;return t.activeOptionIndex===o&&t.activationTrigger===c?t:{...t,...e,isTyping:!1,activeOptionIndex:o,activationTrigger:c,__demoMode:!1}},[4]:(t,n)=>{var d,f,b;if((d=t.dataRef.current)!=null&&d.virtual)return{...t,options:[...t.options,n.payload]};let e=n.payload,o=ge(t,T=>(T.push(e),T));t.activeOptionIndex===null&&(f=t.dataRef.current)!=null&&f.isSelected(n.payload.dataRef.current.value)&&(o.activeOptionIndex=o.options.indexOf(e));let c={...t,...o,activationTrigger:2};return(b=t.dataRef.current)!=null&&b.__demoMode&&t.dataRef.current.value===void 0&&(c.activeOptionIndex=0),c},[5]:(t,n)=>{var o;if((o=t.dataRef.current)!=null&&o.virtual)return{...t,options:t.options.filter(c=>c.id!==n.id)};let e=ge(t,c=>{let d=c.findIndex(f=>f.id===n.id);return d!==-1&&c.splice(d,1),c});return{...t,...e,activationTrigger:2}},[6]:(t,n)=>t.activationTrigger===n.trigger?t:{...t,activationTrigger:n.trigger},[7]:(t,n)=>{var o,c;if(t.virtual===null)return{...t,virtual:{options:n.options,disabled:(o=n.disabled)!=null?o:()=>!1}};if(t.virtual.options===n.options&&t.virtual.disabled===n.disabled)return t;let e=t.activeOptionIndex;if(t.activeOptionIndex!==null){let d=n.options.indexOf(t.virtual.options[t.activeOptionIndex]);d!==-1?e=d:e=null}return{...t,activeOptionIndex:e,virtual:{options:n.options,disabled:(c=n.disabled)!=null?c:()=>!1}}},[8]:(t,n)=>t.inputElement===n.element?t:{...t,inputElement:n.element},[9]:(t,n)=>t.buttonElement===n.element?t:{...t,buttonElement:n.element},[10]:(t,n)=>t.optionsElement===n.element?t:{...t,optionsElement:n.element}},ve=me(null);ve.displayName="ComboboxActionsContext";function le(t){let n=fe(ve);if(n===null){let e=new Error(`<${t} /> is missing a parent <Combobox /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(e,le),e}return n}let we=me(null);function At(t){let n=oe("VirtualProvider"),{options:e}=n.virtual,[o,c]=K(()=>{let r=n.optionsElement;if(!r)return[0,0];let i=window.getComputedStyle(r);return[parseFloat(i.paddingBlockStart||i.paddingTop),parseFloat(i.paddingBlockEnd||i.paddingBottom)]},[n.optionsElement]),d=ke({enabled:e.length!==0,scrollPaddingStart:o,scrollPaddingEnd:c,count:e.length,estimateSize(){return 40},getScrollElement(){return n.optionsElement},overscan:12}),[f,b]=Pe(0);J(()=>{b(r=>r+1)},[e]);let T=d.getVirtualItems();return T.length===0?null:D.createElement(we.Provider,{value:d},D.createElement("div",{style:{position:"relative",width:"100%",height:`${d.getTotalSize()}px`},ref:r=>{if(r){if(typeof process!="undefined"&&process.env.JEST_WORKER_ID!==void 0||n.activationTrigger===0)return;n.activeOptionIndex!==null&&e.length>n.activeOptionIndex&&d.scrollToIndex(n.activeOptionIndex)}}},T.map(r=>{var i;return D.createElement(Ie,{key:r.key},D.cloneElement((i=t.children)==null?void 0:i.call(t,{...t.slot,option:e[r.index]}),{key:`${f}-${r.key}`,"data-index":r.index,"aria-setsize":e.length,"aria-posinset":r.index+1,style:{position:"absolute",top:0,left:0,transform:`translateY(${r.start}px)`,overflowAnchor:"none"}}))})))}let ae=me(null);ae.displayName="ComboboxDataContext";function oe(t){let n=fe(ae);if(n===null){let e=new Error(`<${t} /> is missing a parent <Combobox /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(e,oe),e}return n}function Rt(t,n){return te(n.type,Pt,t,n)}let _t=Ie;function ht(t,n){var ye,Oe;let e=nt(),{value:o,defaultValue:c,onChange:d,form:f,name:b,by:T,disabled:r=e||!1,onClose:i,__demoMode:l=!1,multiple:E=!1,immediate:R=!1,virtual:s=null,nullable:M,...H}=t,_=We(c),[P=E?[]:void 0,O]=Ke(o,d,_),[S,g]=Ue(Rt,{dataRef:He(),comboboxState:l?0:1,isTyping:!1,options:[],virtual:s?{options:s.options,disabled:(ye=s.disabled)!=null?ye:()=>!1}:null,activeOptionIndex:null,activationTrigger:2,inputElement:null,buttonElement:null,optionsElement:null,__demoMode:l}),F=Z(!1),w=Z({static:!1,hold:!1}),x=ze(T),W=m(u=>s?T===null?s.options.indexOf(u):s.options.findIndex(y=>x(y,u)):S.options.findIndex(y=>x(y.dataRef.current.value,u))),j=ce(u=>te(p.mode,{[1]:()=>P.some(y=>x(y,u)),[0]:()=>x(P,u)}),[P]),U=m(u=>S.activeOptionIndex===W(u)),p=K(()=>({...S,immediate:R,optionsPropsRef:w,value:P,defaultValue:_,disabled:r,mode:E?1:0,virtual:s?S.virtual:null,get activeOptionIndex(){if(F.current&&S.activeOptionIndex===null&&(s?s.options.length>0:S.options.length>0)){if(s){let y=s.options.findIndex(z=>{var pe,Ce;return!((Ce=(pe=s.disabled)==null?void 0:pe.call(s,z))!=null&&Ce)});if(y!==-1)return y}let u=S.options.findIndex(y=>!y.dataRef.current.disabled);if(u!==-1)return u}return S.activeOptionIndex},calculateIndex:W,compare:x,isSelected:j,isActive:U}),[P,_,r,E,l,S,s]);J(()=>{var u;s&&g({type:7,options:s.options,disabled:(u=s.disabled)!=null?u:null})},[s,s==null?void 0:s.options,s==null?void 0:s.disabled]),J(()=>{S.dataRef.current=p},[p]);let $=p.comboboxState===0;qe($,[p.buttonElement,p.inputElement,p.optionsElement],()=>V.closeCombobox());let N=K(()=>{var u,y,z;return{open:p.comboboxState===0,disabled:r,activeIndex:p.activeOptionIndex,activeOption:p.activeOptionIndex===null?null:p.virtual?p.virtual.options[(u=p.activeOptionIndex)!=null?u:0]:(z=(y=p.options[p.activeOptionIndex])==null?void 0:y.dataRef.current.value)!=null?z:null,value:P}},[p,r,P]),v=m(()=>{if(p.activeOptionIndex!==null){if(V.setIsTyping(!1),p.virtual)A(p.virtual.options[p.activeOptionIndex]);else{let{dataRef:u}=p.options[p.activeOptionIndex];A(u.current.value)}V.goToOption(I.Specific,p.activeOptionIndex)}}),G=m(()=>{g({type:0}),F.current=!0}),ne=m(()=>{g({type:1}),F.current=!1,i==null||i()}),q=m(u=>{g({type:3,isTyping:u})}),Y=m((u,y,z)=>(F.current=!1,u===I.Specific?g({type:2,focus:I.Specific,idx:y,trigger:z}):g({type:2,focus:u,trigger:z}))),Q=m((u,y)=>(g({type:4,payload:{id:u,dataRef:y}}),()=>{p.isActive(y.current.value)&&(F.current=!0),g({type:5,id:u})})),A=m(u=>te(p.mode,{[0](){return O==null?void 0:O(u)},[1](){let y=p.value.slice(),z=y.findIndex(pe=>x(pe,u));return z===-1?y.push(u):y.splice(z,1),O==null?void 0:O(y)}})),ue=m(u=>{g({type:6,trigger:u})}),a=m(u=>{g({type:8,element:u})}),k=m(u=>{g({type:9,element:u})}),h=m(u=>{g({type:10,element:u})}),V=K(()=>({onChange:A,registerOption:Q,goToOption:Y,setIsTyping:q,closeCombobox:ne,openCombobox:G,setActivationTrigger:ue,selectActiveOption:v,setInputElement:a,setButtonElement:k,setOptionsElement:h}),[]),[C,B]=yt(),X=n===null?{}:{ref:n},Ne=ce(()=>{if(_!==void 0)return O==null?void 0:O(_)},[O,_]);return D.createElement(B,{value:C,props:{htmlFor:(Oe=p.inputElement)==null?void 0:Oe.id},slot:{open:p.comboboxState===0,disabled:r}},D.createElement(it,null,D.createElement(ve.Provider,{value:V},D.createElement(ae.Provider,{value:p},D.createElement(bt,{value:te(p.comboboxState,{[0]:be.Open,[1]:be.Closed})},b!=null&&D.createElement(pt,{disabled:r,data:P!=null?{[b]:P}:{},form:f,onReset:Ne}),re({ourProps:X,theirProps:H,slot:N,defaultTag:_t,name:"Combobox"}))))))}let Mt="input";function Dt(t,n){var q,Y,Q,A,ue;let e=oe("Combobox.Input"),o=le("Combobox.Input"),c=se(),d=dt(),{id:f=d||`headlessui-combobox-input-${c}`,onChange:b,displayValue:T,disabled:r=e.disabled||!1,autoFocus:i=!1,type:l="text",...E}=t,R=Z(null),s=de(R,n,at(),o.setInputElement),M=Re(e.inputElement),H=je(),_=m(()=>{o.onChange(null),e.optionsElement&&(e.optionsElement.scrollTop=0),o.goToOption(I.Nothing)}),P=K(()=>{var a;return typeof T=="function"&&e.value!==void 0?(a=T(e.value))!=null?a:"":typeof e.value=="string"?e.value:""},[e.value,T]);he(([a,k],[h,V])=>{if(e.isTyping)return;let C=R.current;C&&((V===0&&k===1||a!==h)&&(C.value=a),requestAnimationFrame(()=>{if(e.isTyping||!C||(M==null?void 0:M.activeElement)!==C)return;let{selectionStart:B,selectionEnd:X}=C;Math.abs((X!=null?X:0)-(B!=null?B:0))===0&&B===0&&C.setSelectionRange(C.value.length,C.value.length)}))},[P,e.comboboxState,M,e.isTyping]),he(([a],[k])=>{if(a===0&&k===1){if(e.isTyping)return;let h=R.current;if(!h)return;let V=h.value,{selectionStart:C,selectionEnd:B,selectionDirection:X}=h;h.value="",h.value=V,X!==null?h.setSelectionRange(C,B,X):h.setSelectionRange(C,B)}},[e.comboboxState]);let O=Z(!1),S=m(()=>{O.current=!0}),g=m(()=>{H.nextFrame(()=>{O.current=!1})}),F=m(a=>{switch(o.setIsTyping(!0),a.key){case L.Enter:if(e.comboboxState!==0||O.current)return;if(a.preventDefault(),a.stopPropagation(),e.activeOptionIndex===null){o.closeCombobox();return}o.selectActiveOption(),e.mode===0&&o.closeCombobox();break;case L.ArrowDown:return a.preventDefault(),a.stopPropagation(),te(e.comboboxState,{[0]:()=>o.goToOption(I.Next),[1]:()=>o.openCombobox()});case L.ArrowUp:return a.preventDefault(),a.stopPropagation(),te(e.comboboxState,{[0]:()=>o.goToOption(I.Previous),[1]:()=>{ee(()=>o.openCombobox()),e.value||o.goToOption(I.Last)}});case L.Home:if(a.shiftKey)break;return a.preventDefault(),a.stopPropagation(),o.goToOption(I.First);case L.PageUp:return a.preventDefault(),a.stopPropagation(),o.goToOption(I.First);case L.End:if(a.shiftKey)break;return a.preventDefault(),a.stopPropagation(),o.goToOption(I.Last);case L.PageDown:return a.preventDefault(),a.stopPropagation(),o.goToOption(I.Last);case L.Escape:return e.comboboxState!==0?void 0:(a.preventDefault(),e.optionsElement&&!e.optionsPropsRef.current.static&&a.stopPropagation(),e.mode===0&&e.value===null&&_(),o.closeCombobox());case L.Tab:if(e.comboboxState!==0)return;e.mode===0&&e.activationTrigger!==1&&o.selectActiveOption(),o.closeCombobox();break}}),w=m(a=>{b==null||b(a),e.mode===0&&a.target.value===""&&_(),o.openCombobox()}),x=m(a=>{var h,V,C;let k=(h=a.relatedTarget)!=null?h:De.find(B=>B!==a.currentTarget);if(!((V=e.optionsElement)!=null&&V.contains(k))&&!((C=e.buttonElement)!=null&&C.contains(k))&&e.comboboxState===0)return a.preventDefault(),e.mode===0&&e.value===null&&_(),o.closeCombobox()}),W=m(a=>{var h,V,C;let k=(h=a.relatedTarget)!=null?h:De.find(B=>B!==a.currentTarget);(V=e.buttonElement)!=null&&V.contains(k)||(C=e.optionsElement)!=null&&C.contains(k)||e.disabled||e.immediate&&e.comboboxState!==0&&H.microTask(()=>{ee(()=>o.openCombobox()),o.setActivationTrigger(1)})}),j=xe(),U=gt(),{isFocused:p,focusProps:$}=Ee({autoFocus:i}),{isHovered:N,hoverProps:v}=Se({isDisabled:r}),G=K(()=>({open:e.comboboxState===0,disabled:r,hover:N,focus:p,autofocus:i}),[e,N,p,i,r]),ne=Te({ref:s,id:f,role:"combobox",type:l,"aria-controls":(q=e.optionsElement)==null?void 0:q.id,"aria-expanded":e.comboboxState===0,"aria-activedescendant":e.activeOptionIndex===null?void 0:e.virtual?(Y=e.options.find(a=>!a.dataRef.current.disabled&&e.compare(a.dataRef.current.value,e.virtual.options[e.activeOptionIndex])))==null?void 0:Y.id:(Q=e.options[e.activeOptionIndex])==null?void 0:Q.id,"aria-labelledby":j,"aria-describedby":U,"aria-autocomplete":"list",defaultValue:(ue=(A=t.defaultValue)!=null?A:e.defaultValue!==void 0?T==null?void 0:T(e.defaultValue):null)!=null?ue:e.defaultValue,disabled:r||void 0,autoFocus:i,onCompositionStart:S,onCompositionEnd:g,onKeyDown:F,onChange:w,onFocus:W,onBlur:x},$,v);return re({ourProps:ne,theirProps:E,slot:G,defaultTag:Mt,name:"Combobox.Input"})}let Ft="button";function Vt(t,n){var w;let e=oe("Combobox.Button"),o=le("Combobox.Button"),c=de(n,o.setButtonElement),d=xt(),f=se(),{id:b=`headlessui-combobox-button-${f}`,disabled:T=e.disabled||!1,autoFocus:r=!1,...i}=t,l=_e(e.inputElement),E=m(x=>{switch(x.key){case L.Space:case L.Enter:x.preventDefault(),x.stopPropagation(),e.comboboxState===1&&ee(()=>o.openCombobox()),l();return;case L.ArrowDown:x.preventDefault(),x.stopPropagation(),e.comboboxState===1&&(ee(()=>o.openCombobox()),e.value||o.goToOption(I.First)),l();return;case L.ArrowUp:x.preventDefault(),x.stopPropagation(),e.comboboxState===1&&(ee(()=>o.openCombobox()),e.value||o.goToOption(I.Last)),l();return;case L.Escape:if(e.comboboxState!==0)return;x.preventDefault(),e.optionsElement&&!e.optionsPropsRef.current.static&&x.stopPropagation(),ee(()=>o.closeCombobox()),l();return;default:return}}),R=m(x=>{x.preventDefault(),!ct(x.currentTarget)&&(x.button===Be.Left&&(e.comboboxState===0?o.closeCombobox():o.openCombobox()),l())}),s=xe([b]),{isFocusVisible:M,focusProps:H}=Ee({autoFocus:r}),{isHovered:_,hoverProps:P}=Se({isDisabled:T}),{pressed:O,pressProps:S}=Ge({disabled:T}),g=K(()=>({open:e.comboboxState===0,active:O||e.comboboxState===0,disabled:T,value:e.value,hover:_,focus:M}),[e,_,M,O,T]),F=Te({ref:c,id:b,type:Ye(t,e.buttonElement),tabIndex:-1,"aria-haspopup":"listbox","aria-controls":(w=e.optionsElement)==null?void 0:w.id,"aria-expanded":e.comboboxState===0,"aria-labelledby":s,disabled:T||void 0,autoFocus:r,onMouseDown:R,onKeyDown:E},H,P,S);return re({mergeRefs:d,ourProps:F,theirProps:i,slot:g,defaultTag:Ft,name:"Combobox.Button"})}let Lt="div",Bt=Le.RenderStrategy|Le.Static;function wt(t,n){var q,Y,Q;let e=se(),{id:o=`headlessui-combobox-options-${e}`,hold:c=!1,anchor:d,portal:f=!1,modal:b=!0,transition:T=!1,...r}=t,i=oe("Combobox.Options"),l=le("Combobox.Options"),E=ut(d);E&&(f=!0);let[R,s]=rt(E),[M,H]=Pe(null),_=lt(),P=de(n,E?R:null,l.setOptionsElement,H),O=Re(i.optionsElement),S=mt(),[g,F]=tt(T,M,S!==null?(S&be.Open)===be.Open:i.comboboxState===0);Je(g,i.inputElement,l.closeCombobox);let w=i.__demoMode?!1:b&&i.comboboxState===0;Qe(w,O);let x=i.__demoMode?!1:b&&i.comboboxState===0;$e(x,{allowed:ce(()=>[i.inputElement,i.buttonElement,i.optionsElement],[i.inputElement,i.buttonElement,i.optionsElement])}),J(()=>{var A;i.optionsPropsRef.current.static=(A=t.static)!=null?A:!1},[i.optionsPropsRef,t.static]),J(()=>{i.optionsPropsRef.current.hold=c},[i.optionsPropsRef,c]),ot(i.comboboxState===0,{container:i.optionsElement,accept(A){return A.getAttribute("role")==="option"?NodeFilter.FILTER_REJECT:A.hasAttribute("role")?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT},walk(A){A.setAttribute("role","none")}});let W=xe([(q=i.buttonElement)==null?void 0:q.id]),j=K(()=>({open:i.comboboxState===0,option:void 0}),[i.comboboxState]),U=m(()=>{l.setActivationTrigger(0)}),p=m(A=>{A.preventDefault(),l.setActivationTrigger(0)}),$=Te(E?_():{},{"aria-labelledby":W,role:"listbox","aria-multiselectable":i.mode===1?!0:void 0,id:o,ref:P,style:{...r.style,...s,"--input-width":Ae(i.inputElement,!0).width,"--button-width":Ae(i.buttonElement,!0).width},onWheel:i.activationTrigger===0?void 0:U,onMouseDown:p,...et(F)}),N=g&&i.comboboxState===1,v=Me(N,(Y=i.virtual)==null?void 0:Y.options),G=Me(N,i.value),ne=m(A=>i.compare(G,A));if(i.virtual){if(v===void 0)throw new Error("Missing `options` in virtual mode");Object.assign(r,{children:D.createElement(ae.Provider,{value:v!==i.virtual.options?{...i,virtual:{...i.virtual,options:v}}:i},D.createElement(At,{slot:j},r.children))})}return D.createElement(Ot,{enabled:f?t.static||g:!1},D.createElement(ae.Provider,{value:i.mode===1?i:{...i,isSelected:ne}},re({ourProps:$,theirProps:{...r,children:D.createElement(st,{freeze:N},typeof r.children=="function"?(Q=r.children)==null?void 0:Q.call(r,j):r.children)},slot:j,defaultTag:Lt,features:Bt,visible:g,name:"Combobox.Options"})))}let Nt="div";function kt(t,n){var U,p,$,N;let e=oe("Combobox.Option"),o=le("Combobox.Option"),c=se(),{id:d=`headlessui-combobox-option-${c}`,value:f,disabled:b=($=(p=(U=e.virtual)==null?void 0:U.disabled)==null?void 0:p.call(U,f))!=null?$:!1,order:T=null,...r}=t,i=_e(e.inputElement),l=e.virtual?e.activeOptionIndex===e.calculateIndex(f):e.activeOptionIndex===null?!1:((N=e.options[e.activeOptionIndex])==null?void 0:N.id)===d,E=e.isSelected(f),R=Z(null),s=Xe({disabled:b,value:f,domRef:R,order:T}),M=fe(we),H=de(n,R,M?M.measureElement:null),_=m(()=>{o.setIsTyping(!1),o.onChange(f)});J(()=>o.registerOption(d,s),[s,d]);let P=Z(!(e.virtual||e.__demoMode));J(()=>{if(!e.virtual&&!e.__demoMode)return Ve().requestAnimationFrame(()=>{P.current=!0})},[e.virtual,e.__demoMode]),J(()=>{if(P.current&&e.comboboxState===0&&l&&e.activationTrigger!==0)return Ve().requestAnimationFrame(()=>{var v,G;(G=(v=R.current)==null?void 0:v.scrollIntoView)==null||G.call(v,{block:"nearest"})})},[R,l,e.comboboxState,e.activationTrigger,e.activeOptionIndex]);let O=m(v=>{v.preventDefault(),v.button===Be.Left&&(b||(_(),Tt()||requestAnimationFrame(()=>i()),e.mode===0&&o.closeCombobox()))}),S=m(()=>{if(b)return o.goToOption(I.Nothing);let v=e.calculateIndex(f);o.goToOption(I.Specific,v)}),g=Ze(),F=m(v=>g.update(v)),w=m(v=>{if(!g.wasMoved(v)||b||l)return;let G=e.calculateIndex(f);o.goToOption(I.Specific,G,0)}),x=m(v=>{g.wasMoved(v)&&(b||l&&(e.optionsPropsRef.current.hold||o.goToOption(I.Nothing)))}),W=K(()=>({active:l,focus:l,selected:E,disabled:b}),[l,E,b]);return re({ourProps:{id:d,ref:H,role:"option",tabIndex:b===!0?void 0:-1,"aria-disabled":b===!0?!0:void 0,"aria-selected":E,disabled:void 0,onMouseDown:O,onFocus:S,onPointerEnter:F,onMouseEnter:F,onPointerMove:w,onMouseMove:w,onPointerLeave:x,onMouseLeave:x},theirProps:r,slot:W,defaultTag:Nt,name:"Combobox.Option"})}let Ht=ie(ht),Ut=ie(Vt),Gt=ie(Dt),zt=vt,Kt=ie(wt),Wt=ie(kt),Ho=Object.assign(Ht,{Input:Gt,Button:Ut,Label:zt,Options:Kt,Option:Wt});export{Ho as Combobox,Ut as ComboboxButton,Gt as ComboboxInput,zt as ComboboxLabel,Wt as ComboboxOption,Kt as ComboboxOptions}; |
@@ -20,3 +20,3 @@ import React, { type ElementType, type ReactNode, type Ref } from 'react'; | ||
export type DescriptionProps<TTag extends ElementType = typeof DEFAULT_DESCRIPTION_TAG> = Props<TTag>; | ||
declare function DescriptionFn<TTag extends ElementType = typeof DEFAULT_DESCRIPTION_TAG>(props: DescriptionProps<TTag>, ref: Ref<HTMLParagraphElement>): React.ReactElement<any, string | React.JSXElementConstructor<any>> | null; | ||
declare function DescriptionFn<TTag extends ElementType = typeof DEFAULT_DESCRIPTION_TAG>(props: DescriptionProps<TTag>, ref: Ref<HTMLElement>): React.ReactElement<any, string | React.JSXElementConstructor<any>> | null; | ||
export interface _internal_ComponentDescription extends HasDisplayName { | ||
@@ -23,0 +23,0 @@ <TTag extends ElementType = typeof DEFAULT_DESCRIPTION_TAG>(props: DescriptionProps<TTag> & RefProp<typeof DescriptionFn>): JSX.Element; |
@@ -1,1 +0,1 @@ | ||
"use client";import m,{createContext as T,useContext as u,useMemo as c,useState as P}from"react";import{useEvent as g}from'../../hooks/use-event.js';import{useId as x}from'../../hooks/use-id.js';import{useIsoMorphicEffect as y}from'../../hooks/use-iso-morphic-effect.js';import{useSyncRefs as E}from'../../hooks/use-sync-refs.js';import{useDisabled as v}from'../../internal/disabled.js';import{forwardRefWithAs as R,render as I}from'../../utils/render.js';let a=T(null);a.displayName="DescriptionContext";function f(){let r=u(a);if(r===null){let e=new Error("You used a <Description /> component, but it is not inside a relevant parent.");throw Error.captureStackTrace&&Error.captureStackTrace(e,f),e}return r}function G(){var r,e;return(e=(r=u(a))==null?void 0:r.value)!=null?e:void 0}function U(){let[r,e]=P([]);return[r.length>0?r.join(" "):void 0,c(()=>function(t){let i=g(n=>(e(s=>[...s,n]),()=>e(s=>{let o=s.slice(),p=o.indexOf(n);return p!==-1&&o.splice(p,1),o}))),l=c(()=>({register:i,slot:t.slot,name:t.name,props:t.props,value:t.value}),[i,t.slot,t.name,t.props,t.value]);return m.createElement(a.Provider,{value:l},t.children)},[e])]}let S="p";function h(r,e){let d=x(),t=v(),{id:i=`headlessui-description-${d}`,...l}=r,n=f(),s=E(e);y(()=>n.register(i),[i,n.register]);let o=t||!1,p=c(()=>({...n.slot,disabled:o}),[n.slot,o]),D={ref:s,...n.props,id:i};return I({ourProps:D,theirProps:l,slot:p,defaultTag:S,name:n.name||"Description"})}let C=R(h),w=Object.assign(C,{});export{w as Description,G as useDescribedBy,U as useDescriptions}; | ||
"use client";import m,{createContext as T,useContext as u,useMemo as c,useState as P}from"react";import{useEvent as g}from'../../hooks/use-event.js';import{useId as x}from'../../hooks/use-id.js';import{useIsoMorphicEffect as y}from'../../hooks/use-iso-morphic-effect.js';import{useSyncRefs as E}from'../../hooks/use-sync-refs.js';import{useDisabled as v}from'../../internal/disabled.js';import{forwardRefWithAs as R,render as I}from'../../utils/render.js';let a=T(null);a.displayName="DescriptionContext";function f(){let r=u(a);if(r===null){let e=new Error("You used a <Description /> component, but it is not inside a relevant parent.");throw Error.captureStackTrace&&Error.captureStackTrace(e,f),e}return r}function G(){var r,e;return(e=(r=u(a))==null?void 0:r.value)!=null?e:void 0}function U(){let[r,e]=P([]);return[r.length>0?r.join(" "):void 0,c(()=>function(t){let i=g(n=>(e(s=>[...s,n]),()=>e(s=>{let o=s.slice(),p=o.indexOf(n);return p!==-1&&o.splice(p,1),o}))),l=c(()=>({register:i,slot:t.slot,name:t.name,props:t.props,value:t.value}),[i,t.slot,t.name,t.props,t.value]);return m.createElement(a.Provider,{value:l},t.children)},[e])]}let S="p";function C(r,e){let d=x(),t=v(),{id:i=`headlessui-description-${d}`,...l}=r,n=f(),s=E(e);y(()=>n.register(i),[i,n.register]);let o=t||!1,p=c(()=>({...n.slot,disabled:o}),[n.slot,o]),D={ref:s,...n.props,id:i};return I({ourProps:D,theirProps:l,slot:p,defaultTag:S,name:n.name||"Description"})}let _=R(C),w=Object.assign(_,{});export{w as Description,G as useDescribedBy,U as useDescriptions}; |
@@ -17,12 +17,14 @@ import React, { type ElementType, type MutableRefObject, type Ref } from 'react'; | ||
autoFocus?: boolean; | ||
transition?: boolean; | ||
__demoMode?: boolean; | ||
}>; | ||
declare function DialogFn<TTag extends ElementType = typeof DEFAULT_DIALOG_TAG>(props: DialogProps<TTag>, ref: Ref<HTMLDivElement>): React.JSX.Element; | ||
declare let DEFAULT_OVERLAY_TAG: "div"; | ||
type OverlayRenderPropArg = { | ||
declare function DialogFn<TTag extends ElementType = typeof DEFAULT_DIALOG_TAG>(props: DialogProps<TTag>, ref: Ref<HTMLElement>): React.JSX.Element; | ||
declare let DEFAULT_PANEL_TAG: "div"; | ||
type PanelRenderPropArg = { | ||
open: boolean; | ||
}; | ||
type OverlayPropsWeControl = 'aria-hidden'; | ||
export type DialogOverlayProps<TTag extends ElementType = typeof DEFAULT_OVERLAY_TAG> = Props<TTag, OverlayRenderPropArg, OverlayPropsWeControl>; | ||
declare function OverlayFn<TTag extends ElementType = typeof DEFAULT_OVERLAY_TAG>(props: DialogOverlayProps<TTag>, ref: Ref<HTMLDivElement>): React.ReactElement<any, string | React.JSXElementConstructor<any>> | null; | ||
export type DialogPanelProps<TTag extends ElementType = typeof DEFAULT_PANEL_TAG> = Props<TTag, PanelRenderPropArg, never, { | ||
transition?: boolean; | ||
}>; | ||
declare function PanelFn<TTag extends ElementType = typeof DEFAULT_PANEL_TAG>(props: DialogPanelProps<TTag>, ref: Ref<HTMLElement>): React.JSX.Element; | ||
declare let DEFAULT_BACKDROP_TAG: "div"; | ||
@@ -32,11 +34,6 @@ type BackdropRenderPropArg = { | ||
}; | ||
type BackdropPropsWeControl = 'aria-hidden'; | ||
export type DialogBackdropProps<TTag extends ElementType = typeof DEFAULT_BACKDROP_TAG> = Props<TTag, BackdropRenderPropArg, BackdropPropsWeControl>; | ||
declare function BackdropFn<TTag extends ElementType = typeof DEFAULT_BACKDROP_TAG>(props: DialogBackdropProps<TTag>, ref: Ref<HTMLDivElement>): React.JSX.Element; | ||
declare let DEFAULT_PANEL_TAG: "div"; | ||
type PanelRenderPropArg = { | ||
open: boolean; | ||
}; | ||
export type DialogPanelProps<TTag extends ElementType = typeof DEFAULT_PANEL_TAG> = Props<TTag, PanelRenderPropArg>; | ||
declare function PanelFn<TTag extends ElementType = typeof DEFAULT_PANEL_TAG>(props: DialogPanelProps<TTag>, ref: Ref<HTMLDivElement>): React.ReactElement<any, string | React.JSXElementConstructor<any>> | null; | ||
export type DialogBackdropProps<TTag extends ElementType = typeof DEFAULT_BACKDROP_TAG> = Props<TTag, BackdropRenderPropArg, never, { | ||
transition?: boolean; | ||
}>; | ||
declare function BackdropFn<TTag extends ElementType = typeof DEFAULT_BACKDROP_TAG>(props: DialogBackdropProps<TTag>, ref: Ref<HTMLElement>): React.JSX.Element; | ||
declare let DEFAULT_TITLE_TAG: "h2"; | ||
@@ -47,14 +44,11 @@ type TitleRenderPropArg = { | ||
export type DialogTitleProps<TTag extends ElementType = typeof DEFAULT_TITLE_TAG> = Props<TTag, TitleRenderPropArg>; | ||
declare function TitleFn<TTag extends ElementType = typeof DEFAULT_TITLE_TAG>(props: DialogTitleProps<TTag>, ref: Ref<HTMLHeadingElement>): React.ReactElement<any, string | React.JSXElementConstructor<any>> | null; | ||
declare function TitleFn<TTag extends ElementType = typeof DEFAULT_TITLE_TAG>(props: DialogTitleProps<TTag>, ref: Ref<HTMLElement>): React.ReactElement<any, string | React.JSXElementConstructor<any>> | null; | ||
export interface _internal_ComponentDialog extends HasDisplayName { | ||
<TTag extends ElementType = typeof DEFAULT_DIALOG_TAG>(props: DialogProps<TTag> & RefProp<typeof DialogFn>): JSX.Element; | ||
} | ||
export interface _internal_ComponentDialogBackdrop extends HasDisplayName { | ||
<TTag extends ElementType = typeof DEFAULT_BACKDROP_TAG>(props: DialogBackdropProps<TTag> & RefProp<typeof BackdropFn>): JSX.Element; | ||
} | ||
export interface _internal_ComponentDialogPanel extends HasDisplayName { | ||
<TTag extends ElementType = typeof DEFAULT_PANEL_TAG>(props: DialogPanelProps<TTag> & RefProp<typeof PanelFn>): JSX.Element; | ||
} | ||
export interface _internal_ComponentDialogOverlay extends HasDisplayName { | ||
<TTag extends ElementType = typeof DEFAULT_OVERLAY_TAG>(props: DialogOverlayProps<TTag> & RefProp<typeof OverlayFn>): JSX.Element; | ||
export interface _internal_ComponentDialogBackdrop extends HasDisplayName { | ||
<TTag extends ElementType = typeof DEFAULT_BACKDROP_TAG>(props: DialogBackdropProps<TTag> & RefProp<typeof BackdropFn>): JSX.Element; | ||
} | ||
@@ -66,5 +60,4 @@ export interface _internal_ComponentDialogTitle extends HasDisplayName { | ||
} | ||
export declare let DialogPanel: _internal_ComponentDialogPanel; | ||
export declare let DialogBackdrop: _internal_ComponentDialogBackdrop; | ||
export declare let DialogPanel: _internal_ComponentDialogPanel; | ||
export declare let DialogOverlay: _internal_ComponentDialogOverlay; | ||
export declare let DialogTitle: _internal_ComponentDialogTitle; | ||
@@ -74,5 +67,5 @@ /** @deprecated use `<Description>` instead of `<DialogDescription>` */ | ||
export declare let Dialog: _internal_ComponentDialog & { | ||
Backdrop: _internal_ComponentDialogBackdrop; | ||
/** @deprecated use `<DialogPanel>` instead of `<Dialog.Panel>` */ | ||
Panel: _internal_ComponentDialogPanel; | ||
Overlay: _internal_ComponentDialogOverlay; | ||
/** @deprecated use `<DialogTitle>` instead of `<Dialog.Title>` */ | ||
Title: _internal_ComponentDialogTitle; | ||
@@ -79,0 +72,0 @@ /** @deprecated use `<Description>` instead of `<Dialog.Description>` */ |
@@ -1,1 +0,1 @@ | ||
"use client";import i,{createContext as Ae,createRef as _e,useCallback as V,useContext as X,useEffect as q,useMemo as P,useReducer as Re,useRef as z,useState as Ce}from"react";import{useDocumentOverflowLockedEffect as ve}from'../../hooks/document-overflow/use-document-overflow.js';import{useEvent as _}from'../../hooks/use-event.js';import{useEventListener as Oe}from'../../hooks/use-event-listener.js';import{useId as R}from'../../hooks/use-id.js';import{useInert as Q}from'../../hooks/use-inert.js';import{useIsTouchDevice as Fe}from'../../hooks/use-is-touch-device.js';import{useOnDisappear as Le}from'../../hooks/use-on-disappear.js';import{useOutsideClick as be}from'../../hooks/use-outside-click.js';import{useOwnerDocument as xe}from'../../hooks/use-owner.js';import{useRootContainers as Se}from'../../hooks/use-root-containers.js';import{useServerHandoffComplete as he}from'../../hooks/use-server-handoff-complete.js';import{useSyncRefs as C}from'../../hooks/use-sync-refs.js';import{CloseProvider as ke}from'../../internal/close-provider.js';import{HoistFormFields as Ie}from'../../internal/form-fields.js';import{State as h,useOpenClosed as Me}from'../../internal/open-closed.js';import{ForcePortalRoot as H}from'../../internal/portal-force-root.js';import{StackMessage as Z,StackProvider as Ge}from'../../internal/stack-context.js';import{isDisabledReactIssue7711 as He}from'../../utils/bugs.js';import{match as B}from'../../utils/match.js';import{RenderFeatures as ee,forwardRefWithAs as v,render as O}from'../../utils/render.js';import{Description as te,useDescriptions as Be}from'../description/description.js';import{FocusTrap as Ue,FocusTrapFeatures as E}from'../focus-trap/focus-trap.js';import{Keys as Ne}from'../keyboard.js';import{Portal as U,useNestedPortals as we}from'../portal/portal.js';var We=(o=>(o[o.Open=0]="Open",o[o.Closed=1]="Closed",o))(We||{}),Ye=(e=>(e[e.SetTitleId=0]="SetTitleId",e))(Ye||{});let $e={[0](t,e){return t.titleId===e.id?t:{...t,titleId:e.id}}},k=Ae(null);k.displayName="DialogContext";function F(t){let e=X(k);if(e===null){let o=new Error(`<${t} /> is missing a parent <Dialog /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(o,F),o}return e}function je(t,e,o=()=>[document.body]){ve(t,e,s=>{var l;return{containers:[...(l=s.containers)!=null?l:[],o]}})}function Je(t,e){return B(e.type,$e,t,e)}let Ke="div",Ve=ee.RenderStrategy|ee.Static;function Xe(t,e){let o=R(),{id:s=`headlessui-dialog-${o}`,open:l,onClose:a,initialFocus:p,role:n="dialog",autoFocus:T=!0,__demoMode:D=!1,...I}=t,[u,N]=Ce(0),w=z(!1);n=function(){return n==="dialog"||n==="alertdialog"?n:(w.current||(w.current=!0,console.warn(`Invalid role [${n}] passed to <Dialog />. Only \`dialog\` and and \`alertdialog\` are supported. Using \`dialog\` instead.`)),"dialog")}();let A=Me();l===void 0&&A!==null&&(l=(A&h.Open)===h.Open);let m=z(null),oe=C(m,e),f=xe(m),W=t.hasOwnProperty("open")||A!==null,Y=t.hasOwnProperty("onClose");if(!W&&!Y)throw new Error("You have to provide an `open` and an `onClose` prop to the `Dialog` component.");if(!W)throw new Error("You provided an `onClose` prop to the `Dialog`, but forgot an `open` prop.");if(!Y)throw new Error("You provided an `open` prop to the `Dialog`, but forgot an `onClose` prop.");if(typeof l!="boolean")throw new Error(`You provided an \`open\` prop to the \`Dialog\`, but the value is not a boolean. Received: ${l}`);if(typeof a!="function")throw new Error(`You provided an \`onClose\` prop to the \`Dialog\`, but the value is not a function. Received: ${a}`);let d=l?0:1,[L,re]=Re(Je,{titleId:null,descriptionId:null,panelRef:_e()}),y=_(()=>a(!1)),$=_(r=>re({type:0,id:r})),b=he()?D?!1:d===0:!1,x=u>1,j=X(k)!==null,[le,ae]=we(),ne={get current(){var r;return(r=L.panelRef.current)!=null?r:m.current}},{resolveContainers:M,mainTreeNodeRef:S,MainTreeNode:ie}=Se({portals:le,defaultContainers:[ne]}),se=x?"parent":"leaf",J=A!==null?(A&h.Closing)===h.Closing:!1,pe=(()=>j||J?!1:b)(),de=V(()=>{var r,c;return(c=Array.from((r=f==null?void 0:f.querySelectorAll("body > *"))!=null?r:[]).find(g=>g.id==="headlessui-portal-root"?!1:g.contains(S.current)&&g instanceof HTMLElement))!=null?c:null},[S]);Q(de,pe);let ue=(()=>x?!0:b)(),fe=V(()=>{var r,c;return(c=Array.from((r=f==null?void 0:f.querySelectorAll("[data-headlessui-portal]"))!=null?r:[]).find(g=>g.contains(S.current)&&g instanceof HTMLElement))!=null?c:null},[S]);Q(fe,ue);let ge=(()=>!(!b||x))();be(M,r=>{r.preventDefault(),y()},ge);let Te=(()=>!(x||d!==0))();Oe(f==null?void 0:f.defaultView,"keydown",r=>{Te&&(r.defaultPrevented||r.key===Ne.Escape&&(r.preventDefault(),r.stopPropagation(),y()))});let ce=(()=>!(J||d!==0||j))();je(f,ce,M),Le(m,y,d===0);let[De,me]=Be(),ye=P(()=>[{dialogState:d,close:y,setTitleId:$},L],[d,L,y,$]),K=P(()=>({open:d===0}),[d]),Pe={ref:oe,id:s,role:n,tabIndex:-1,"aria-modal":d===0?!0:void 0,"aria-labelledby":L.titleId,"aria-describedby":De},Ee=!Fe(),G=b?B(se,{parent:E.RestoreFocus,leaf:E.All&~E.FocusLock}):E.None;return T&&(G|=E.AutoFocus),Ee||(G&=~E.InitialFocus),i.createElement(Ge,{type:"Dialog",enabled:d===0,element:m,onUpdate:_((r,c)=>{c!=="Dialog"&&c!=="Modal"||B(r,{[Z.Add]:()=>N(g=>g+1),[Z.Remove]:()=>N(g=>g-1)})})},i.createElement(H,{force:!0},i.createElement(U,null,i.createElement(k.Provider,{value:ye},i.createElement(U.Group,{target:m},i.createElement(H,{force:!1},i.createElement(me,{slot:K,name:"Dialog.Description"},i.createElement(ae,null,i.createElement(Ue,{initialFocus:p,initialFocusFallback:m,containers:M,features:G},i.createElement(ke,{value:y},O({ourProps:Pe,theirProps:I,slot:K,defaultTag:Ke,features:Ve,visible:d===0,name:"Dialog"})))))))))),i.createElement(Ie,null,i.createElement(ie,null)))}let qe="div";function ze(t,e){let o=R(),{id:s=`headlessui-dialog-overlay-${o}`,...l}=t,[{dialogState:a,close:p}]=F("Dialog.Overlay"),n=C(e),T=_(u=>{if(u.target===u.currentTarget){if(He(u.currentTarget))return u.preventDefault();u.preventDefault(),u.stopPropagation(),p()}}),D=P(()=>({open:a===0}),[a]);return O({ourProps:{ref:n,id:s,"aria-hidden":!0,onClick:T},theirProps:l,slot:D,defaultTag:qe,name:"Dialog.Overlay"})}let Qe="div";function Ze(t,e){let o=R(),{id:s=`headlessui-dialog-backdrop-${o}`,...l}=t,[{dialogState:a},p]=F("Dialog.Backdrop"),n=C(e);q(()=>{if(p.panelRef.current===null)throw new Error("A <Dialog.Backdrop /> component is being used, but a <Dialog.Panel /> component is missing.")},[p.panelRef]);let T=P(()=>({open:a===0}),[a]);return i.createElement(H,{force:!0},i.createElement(U,null,O({ourProps:{ref:n,id:s,"aria-hidden":!0},theirProps:l,slot:T,defaultTag:Qe,name:"Dialog.Backdrop"})))}let et="div";function tt(t,e){let o=R(),{id:s=`headlessui-dialog-panel-${o}`,...l}=t,[{dialogState:a},p]=F("Dialog.Panel"),n=C(e,p.panelRef),T=P(()=>({open:a===0}),[a]),D=_(u=>{u.stopPropagation()});return O({ourProps:{ref:n,id:s,onClick:D},theirProps:l,slot:T,defaultTag:et,name:"Dialog.Panel"})}let ot="h2";function rt(t,e){let o=R(),{id:s=`headlessui-dialog-title-${o}`,...l}=t,[{dialogState:a,setTitleId:p}]=F("Dialog.Title"),n=C(e);q(()=>(p(s),()=>p(null)),[s,p]);let T=P(()=>({open:a===0}),[a]);return O({ourProps:{ref:n,id:s},theirProps:l,slot:T,defaultTag:ot,name:"Dialog.Title"})}let lt=v(Xe),at=v(Ze),nt=v(tt),it=v(ze),st=v(rt),Mt=te,Gt=Object.assign(lt,{Backdrop:at,Panel:nt,Overlay:it,Title:st,Description:te});export{Gt as Dialog,at as DialogBackdrop,Mt as DialogDescription,it as DialogOverlay,nt as DialogPanel,st as DialogTitle}; | ||
"use client";import n,{Fragment as H,createContext as le,createRef as ae,useContext as ie,useEffect as pe,useMemo as E,useReducer as se,useRef as N}from"react";import{useEscape as de}from'../../hooks/use-escape.js';import{useEvent as A}from'../../hooks/use-event.js';import{useId as I}from'../../hooks/use-id.js';import{useInertOthers as ue}from'../../hooks/use-inert-others.js';import{useIsTouchDevice as Te}from'../../hooks/use-is-touch-device.js';import{useOnDisappear as fe}from'../../hooks/use-on-disappear.js';import{useOutsideClick as ge}from'../../hooks/use-outside-click.js';import{useOwnerDocument as me}from'../../hooks/use-owner.js';import{MainTreeProvider as W,useMainTreeNode as ce,useRootContainers as De}from'../../hooks/use-root-containers.js';import{useScrollLock as Pe}from'../../hooks/use-scroll-lock.js';import{useServerHandoffComplete as ye}from'../../hooks/use-server-handoff-complete.js';import{useSyncRefs as M}from'../../hooks/use-sync-refs.js';import{CloseProvider as Ee}from'../../internal/close-provider.js';import{ResetOpenClosedProvider as Ae,State as R,useOpenClosed as $}from'../../internal/open-closed.js';import{ForcePortalRoot as j}from'../../internal/portal-force-root.js';import{match as _e}from'../../utils/match.js';import{RenderFeatures as Y,forwardRefWithAs as _,render as x}from'../../utils/render.js';import{Description as J,useDescriptions as Ce}from'../description/description.js';import{FocusTrap as Fe,FocusTrapFeatures as C}from'../focus-trap/focus-trap.js';import{Portal as be,PortalGroup as ve,useNestedPortals as Re}from'../portal/portal.js';import{Transition as xe,TransitionChild as K}from'../transition/transition.js';var Le=(o=>(o[o.Open=0]="Open",o[o.Closed=1]="Closed",o))(Le||{}),Oe=(t=>(t[t.SetTitleId=0]="SetTitleId",t))(Oe||{});let he={[0](e,t){return e.titleId===t.id?e:{...e,titleId:t.id}}},w=le(null);w.displayName="DialogContext";function L(e){let t=ie(w);if(t===null){let o=new Error(`<${e} /> is missing a parent <Dialog /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(o,L),o}return t}function Se(e,t){return _e(t.type,he,e,t)}let X=_(function(t,o){let a=I(),{id:l=`headlessui-dialog-${a}`,open:i,onClose:p,initialFocus:d,role:s="dialog",autoFocus:c=!0,__demoMode:f=!1,unmount:D=!1,...O}=t,h=N(!1);s=function(){return s==="dialog"||s==="alertdialog"?s:(h.current||(h.current=!0,console.warn(`Invalid role [${s}] passed to <Dialog />. Only \`dialog\` and and \`alertdialog\` are supported. Using \`dialog\` instead.`)),"dialog")}();let P=$();i===void 0&&P!==null&&(i=(P&R.Open)===R.Open);let u=N(null),V=M(u,o),F=me(u),T=i?0:1,[b,q]=se(Se,{titleId:null,descriptionId:null,panelRef:ae()}),g=A(()=>p(!1)),G=A(r=>q({type:0,id:r})),m=ye()?T===0:!1,[z,Q]=Re(),Z={get current(){var r;return(r=b.panelRef.current)!=null?r:u.current}},v=ce(),{resolveContainers:S}=De({mainTreeNode:v,portals:z,defaultContainers:[Z]}),k=P!==null?(P&R.Closing)===R.Closing:!1;ue(f||k?!1:m,{allowed:A(()=>{var r,U;return[(U=(r=u.current)==null?void 0:r.closest("[data-headlessui-portal]"))!=null?U:null]}),disallowed:A(()=>{var r;return[(r=v==null?void 0:v.closest("body > *:not(#headlessui-portal-root)"))!=null?r:null]})}),ge(m,S,r=>{r.preventDefault(),g()}),de(m,F==null?void 0:F.defaultView,r=>{r.preventDefault(),r.stopPropagation(),document.activeElement&&"blur"in document.activeElement&&typeof document.activeElement.blur=="function"&&document.activeElement.blur(),g()}),Pe(f||k?!1:m,F,S),fe(m,u,g);let[ee,te]=Ce(),oe=E(()=>[{dialogState:T,close:g,setTitleId:G,unmount:D},b],[T,b,g,G,D]),B=E(()=>({open:T===0}),[T]),ne={ref:V,id:l,role:s,tabIndex:-1,"aria-modal":f?void 0:T===0?!0:void 0,"aria-labelledby":b.titleId,"aria-describedby":ee,unmount:D},re=!Te(),y=C.None;return m&&!f&&(y|=C.RestoreFocus,y|=C.TabLock,c&&(y|=C.AutoFocus),re&&(y|=C.InitialFocus)),n.createElement(Ae,null,n.createElement(j,{force:!0},n.createElement(be,null,n.createElement(w.Provider,{value:oe},n.createElement(ve,{target:u},n.createElement(j,{force:!1},n.createElement(te,{slot:B},n.createElement(Q,null,n.createElement(Fe,{initialFocus:d,initialFocusFallback:u,containers:S,features:y},n.createElement(Ee,{value:g},x({ourProps:ne,theirProps:O,slot:B,defaultTag:Ie,features:Me,visible:T===0,name:"Dialog"})))))))))))}),Ie="div",Me=Y.RenderStrategy|Y.Static;function we(e,t){let{transition:o=!1,open:a,...l}=e,i=$(),p=e.hasOwnProperty("open")||i!==null,d=e.hasOwnProperty("onClose");if(!p&&!d)throw new Error("You have to provide an `open` and an `onClose` prop to the `Dialog` component.");if(!p)throw new Error("You provided an `onClose` prop to the `Dialog`, but forgot an `open` prop.");if(!d)throw new Error("You provided an `open` prop to the `Dialog`, but forgot an `onClose` prop.");if(!i&&typeof e.open!="boolean")throw new Error(`You provided an \`open\` prop to the \`Dialog\`, but the value is not a boolean. Received: ${e.open}`);if(typeof e.onClose!="function")throw new Error(`You provided an \`onClose\` prop to the \`Dialog\`, but the value is not a function. Received: ${e.onClose}`);return(a!==void 0||o)&&!l.static?n.createElement(W,null,n.createElement(xe,{show:a,transition:o,unmount:l.unmount},n.createElement(X,{ref:t,...l}))):n.createElement(W,null,n.createElement(X,{ref:t,open:a,...l}))}let Ge="div";function ke(e,t){let o=I(),{id:a=`headlessui-dialog-panel-${o}`,transition:l=!1,...i}=e,[{dialogState:p,unmount:d},s]=L("Dialog.Panel"),c=M(t,s.panelRef),f=E(()=>({open:p===0}),[p]),D=A(u=>{u.stopPropagation()}),O={ref:c,id:a,onClick:D};return n.createElement(l?K:H,{...l?{unmount:d}:{}},x({ourProps:O,theirProps:i,slot:f,defaultTag:Ge,name:"Dialog.Panel"}))}let Be="div";function Ue(e,t){let{transition:o=!1,...a}=e,[{dialogState:l,unmount:i}]=L("Dialog.Backdrop"),p=E(()=>({open:l===0}),[l]),d={ref:t,"aria-hidden":!0};return n.createElement(o?K:H,{...o?{unmount:i}:{}},x({ourProps:d,theirProps:a,slot:p,defaultTag:Be,name:"Dialog.Backdrop"}))}let He="h2";function Ne(e,t){let o=I(),{id:a=`headlessui-dialog-title-${o}`,...l}=e,[{dialogState:i,setTitleId:p}]=L("Dialog.Title"),d=M(t);pe(()=>(p(a),()=>p(null)),[a,p]);let s=E(()=>({open:i===0}),[i]);return x({ourProps:{ref:d,id:a},theirProps:l,slot:s,defaultTag:He,name:"Dialog.Title"})}let We=_(we),$e=_(ke),ct=_(Ue),je=_(Ne),Dt=J,Pt=Object.assign(We,{Panel:$e,Title:je,Description:J});export{Pt as Dialog,ct as DialogBackdrop,Dt as DialogDescription,$e as DialogPanel,je as DialogTitle}; |
@@ -38,4 +38,6 @@ import React, { type ElementType, type MutableRefObject, type Ref } from 'react'; | ||
declare let PanelRenderFeatures: number; | ||
export type DisclosurePanelProps<TTag extends ElementType = typeof DEFAULT_PANEL_TAG> = Props<TTag, PanelRenderPropArg, DisclosurePanelPropsWeControl, PropsForFeatures<typeof PanelRenderFeatures>>; | ||
declare function PanelFn<TTag extends ElementType = typeof DEFAULT_PANEL_TAG>(props: DisclosurePanelProps<TTag>, ref: Ref<HTMLDivElement>): React.JSX.Element; | ||
export type DisclosurePanelProps<TTag extends ElementType = typeof DEFAULT_PANEL_TAG> = Props<TTag, PanelRenderPropArg, DisclosurePanelPropsWeControl, { | ||
transition?: boolean; | ||
} & PropsForFeatures<typeof PanelRenderFeatures>>; | ||
declare function PanelFn<TTag extends ElementType = typeof DEFAULT_PANEL_TAG>(props: DisclosurePanelProps<TTag>, ref: Ref<HTMLElement>): React.JSX.Element; | ||
export interface _internal_ComponentDisclosure extends HasDisplayName { | ||
@@ -53,5 +55,7 @@ <TTag extends ElementType = typeof DEFAULT_DISCLOSURE_TAG>(props: DisclosureProps<TTag> & RefProp<typeof DisclosureFn>): JSX.Element; | ||
export declare let Disclosure: _internal_ComponentDisclosure & { | ||
/** @deprecated use `<DisclosureButton>` instead of `<Disclosure.Button>` */ | ||
Button: _internal_ComponentDisclosureButton; | ||
/** @deprecated use `<DisclosurePanel>` instead of `<Disclosure.Panel>` */ | ||
Panel: _internal_ComponentDisclosurePanel; | ||
}; | ||
export {}; |
@@ -1,1 +0,1 @@ | ||
"use client";import{useFocusRing as Q}from"@react-aria/focus";import{useHover as Y}from"@react-aria/interactions";import g,{Fragment as K,createContext as x,useContext as L,useEffect as j,useMemo as b,useReducer as Z,useRef as R}from"react";import{useActivePress as ee}from'../../hooks/use-active-press.js';import{useEvent as A}from'../../hooks/use-event.js';import{useId as W}from'../../hooks/use-id.js';import{useResolveButtonType as te}from'../../hooks/use-resolve-button-type.js';import{optionalRef as ne,useSyncRefs as v}from'../../hooks/use-sync-refs.js';import{CloseProvider as oe}from'../../internal/close-provider.js';import{OpenClosedProvider as le,State as C,useOpenClosed as re}from'../../internal/open-closed.js';import{isDisabledReactIssue7711 as se}from'../../utils/bugs.js';import{match as O}from'../../utils/match.js';import{getOwnerDocument as ie}from'../../utils/owner.js';import{RenderFeatures as $,forwardRefWithAs as _,mergeProps as J,render as B,useMergeRefsFn as X}from'../../utils/render.js';import{startTransition as ue}from'../../utils/start-transition.js';import{Keys as S}from'../keyboard.js';var ae=(o=>(o[o.Open=0]="Open",o[o.Closed=1]="Closed",o))(ae||{}),pe=(t=>(t[t.ToggleDisclosure=0]="ToggleDisclosure",t[t.CloseDisclosure=1]="CloseDisclosure",t[t.SetButtonId=2]="SetButtonId",t[t.SetPanelId=3]="SetPanelId",t[t.LinkPanel=4]="LinkPanel",t[t.UnlinkPanel=5]="UnlinkPanel",t))(pe||{});let ce={[0]:e=>({...e,disclosureState:O(e.disclosureState,{[0]:1,[1]:0})}),[1]:e=>e.disclosureState===1?e:{...e,disclosureState:1},[4](e){return e.linkedPanel===!0?e:{...e,linkedPanel:!0}},[5](e){return e.linkedPanel===!1?e:{...e,linkedPanel:!1}},[2](e,n){return e.buttonId===n.buttonId?e:{...e,buttonId:n.buttonId}},[3](e,n){return e.panelId===n.panelId?e:{...e,panelId:n.panelId}}},M=x(null);M.displayName="DisclosureContext";function F(e){let n=L(M);if(n===null){let o=new Error(`<${e} /> is missing a parent <Disclosure /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(o,F),o}return n}let k=x(null);k.displayName="DisclosureAPIContext";function V(e){let n=L(k);if(n===null){let o=new Error(`<${e} /> is missing a parent <Disclosure /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(o,V),o}return n}let H=x(null);H.displayName="DisclosurePanelContext";function de(){return L(H)}function fe(e,n){return O(n.type,ce,e,n)}let Te=K;function De(e,n){let{defaultOpen:o=!1,...d}=e,i=R(null),r=v(n,ne(c=>{i.current=c},e.as===void 0||e.as===K)),t=R(null),l=R(null),u=Z(fe,{disclosureState:o?0:1,linkedPanel:!1,buttonRef:l,panelRef:t,buttonId:null,panelId:null}),[{disclosureState:f,buttonId:s},T]=u,p=A(c=>{T({type:1});let P=ie(i);if(!P||!s)return;let y=(()=>c?c instanceof HTMLElement?c:c.current instanceof HTMLElement?c.current:P.getElementById(s):P.getElementById(s))();y==null||y.focus()}),m=b(()=>({close:p}),[p]),D=b(()=>({open:f===0,close:p}),[f,p]),I={ref:r};return g.createElement(M.Provider,{value:u},g.createElement(k.Provider,{value:m},g.createElement(oe,{value:p},g.createElement(le,{value:O(f,{[0]:C.Open,[1]:C.Closed})},B({ourProps:I,theirProps:d,slot:D,defaultTag:Te,name:"Disclosure"})))))}let Pe="button";function ye(e,n){let o=W(),{id:d=`headlessui-disclosure-button-${o}`,disabled:i=!1,autoFocus:r=!1,...t}=e,[l,u]=F("Disclosure.Button"),f=de(),s=f===null?!1:f===l.panelId,T=R(null),p=v(T,n,s?null:l.buttonRef),m=X();j(()=>{if(!s)return u({type:2,buttonId:d}),()=>{u({type:2,buttonId:null})}},[d,u,s]);let D=A(a=>{var E;if(s){if(l.disclosureState===1)return;switch(a.key){case S.Space:case S.Enter:a.preventDefault(),a.stopPropagation(),u({type:0}),(E=l.buttonRef.current)==null||E.focus();break}}else switch(a.key){case S.Space:case S.Enter:a.preventDefault(),a.stopPropagation(),u({type:0});break}}),I=A(a=>{switch(a.key){case S.Space:a.preventDefault();break}}),c=A(a=>{var E;se(a.currentTarget)||i||(s?(u({type:0}),(E=l.buttonRef.current)==null||E.focus()):u({type:0}))}),{isFocusVisible:P,focusProps:y}=Q({autoFocus:r}),{isHovered:U,hoverProps:h}=Y({isDisabled:i}),{pressed:N,pressProps:w}=ee({disabled:i}),q=b(()=>({open:l.disclosureState===0,hover:U,active:N,disabled:i,focus:P,autofocus:r}),[l,U,N,P,i,r]),G=te(e,T),z=s?J({ref:p,type:G,disabled:i||void 0,autoFocus:r,onKeyDown:D,onClick:c},y,h,w):J({ref:p,id:d,type:G,"aria-expanded":l.disclosureState===0,"aria-controls":l.linkedPanel?l.panelId:void 0,disabled:i||void 0,autoFocus:r,onKeyDown:D,onKeyUp:I,onClick:c},y,h,w);return B({mergeRefs:m,ourProps:z,theirProps:t,slot:q,defaultTag:Pe,name:"Disclosure.Button"})}let me="div",Ee=$.RenderStrategy|$.Static;function ge(e,n){let o=W(),{id:d=`headlessui-disclosure-panel-${o}`,...i}=e,[r,t]=F("Disclosure.Panel"),{close:l}=V("Disclosure.Panel"),u=X(),f=v(n,r.panelRef,D=>{ue(()=>t({type:D?4:5}))});j(()=>(t({type:3,panelId:d}),()=>{t({type:3,panelId:null})}),[d,t]);let s=re(),T=(()=>s!==null?(s&C.Open)===C.Open:r.disclosureState===0)(),p=b(()=>({open:r.disclosureState===0,close:l}),[r,l]),m={ref:f,id:d};return g.createElement(H.Provider,{value:r.panelId},B({mergeRefs:u,ourProps:m,theirProps:i,slot:p,defaultTag:me,features:Ee,visible:T,name:"Disclosure.Panel"}))}let Se=_(De),be=_(ye),Re=_(ge),we=Object.assign(Se,{Button:be,Panel:Re});export{we as Disclosure,be as DisclosureButton,Re 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}; |
import { type ElementType } from 'react'; | ||
import type { Props } from '../../types.js'; | ||
import { type HasDisplayName } from '../../utils/render.js'; | ||
declare let DEFAULT_FIELDSET_TAG: "div"; | ||
declare let DEFAULT_FIELDSET_TAG: "fieldset"; | ||
type FieldsetRenderPropArg = {}; | ||
type FieldsetPropsWeControl = 'aria-controls'; | ||
type FieldsetPropsWeControl = 'aria-labelledby' | 'aria-disabled' | 'role'; | ||
export type FieldsetProps<TTag extends ElementType = typeof DEFAULT_FIELDSET_TAG> = Props<TTag, FieldsetRenderPropArg, FieldsetPropsWeControl, { | ||
@@ -8,0 +8,0 @@ disabled?: boolean; |
@@ -1,1 +0,1 @@ | ||
"use client";import t,{useMemo as a}from"react";import{DisabledProvider as n,useDisabled as T}from'../../internal/disabled.js';import{forwardRefWithAs as m,render as F}from'../../utils/render.js';import{useLabels as y}from'../label/label.js';let f="div";function E(r,l){let o=T(),{disabled:e=o||!1,...s}=r,[i,d]=y(),p=a(()=>({disabled:e}),[e]);return t.createElement(n,{value:e},t.createElement(d,null,F({ourProps:{ref:l,role:"group","aria-labelledby":i,"aria-disabled":e||void 0},theirProps:s,slot:p,defaultTag:f,name:"Fieldset"})))}let L=m(E);export{L as Fieldset}; | ||
"use client";import o,{useMemo as y}from"react";import{useResolvedTag as F}from'../../hooks/use-resolved-tag.js';import{useSyncRefs as b}from'../../hooks/use-sync-refs.js';import{DisabledProvider as E,useDisabled as P}from'../../internal/disabled.js';import{forwardRefWithAs as u,render as g}from'../../utils/render.js';import{useLabels as D}from'../label/label.js';let d="fieldset";function A(t,i){var s;let a=P(),{disabled:e=a||!1,...p}=t,[n,T]=F((s=t.as)!=null?s:d),l=b(i,T),[r,f]=D(),m=y(()=>({disabled:e}),[e]);return o.createElement(E,{value:e},o.createElement(f,null,g({ourProps:n==="fieldset"?{ref:l,"aria-labelledby":r,disabled:e||void 0}:{ref:l,role:"group","aria-labelledby":r,"aria-disabled":e||void 0},theirProps:p,slot:m,defaultTag:d,name:"Fieldset"})))}let C=u(A);export{C as Fieldset}; |
@@ -8,15 +8,13 @@ import React, { type ElementType, type MutableRefObject, type Ref } from 'react'; | ||
/** No features enabled for the focus trap. */ | ||
None = 1, | ||
None = 0, | ||
/** Ensure that we move focus initially into the container. */ | ||
InitialFocus = 2, | ||
InitialFocus = 1, | ||
/** Ensure that pressing `Tab` and `Shift+Tab` is trapped within the container. */ | ||
TabLock = 4, | ||
TabLock = 2, | ||
/** Ensure that programmatically moving focus outside of the container is disallowed. */ | ||
FocusLock = 8, | ||
FocusLock = 4, | ||
/** Ensure that we restore the focus when unmounting the focus trap. */ | ||
RestoreFocus = 16, | ||
RestoreFocus = 8, | ||
/** Initial focus should look for the `data-autofocus` */ | ||
AutoFocus = 32, | ||
/** Enable all features. */ | ||
All = 30 | ||
AutoFocus = 16 | ||
} | ||
@@ -31,3 +29,3 @@ type FocusTrapRenderPropArg = {}; | ||
}>; | ||
declare function FocusTrapFn<TTag extends ElementType = typeof DEFAULT_FOCUS_TRAP_TAG>(props: FocusTrapProps<TTag>, ref: Ref<HTMLDivElement>): React.JSX.Element; | ||
declare function FocusTrapFn<TTag extends ElementType = typeof DEFAULT_FOCUS_TRAP_TAG>(props: FocusTrapProps<TTag>, ref: Ref<HTMLElement>): React.JSX.Element; | ||
export interface _internal_ComponentFocusTrap extends HasDisplayName { | ||
@@ -37,4 +35,5 @@ <TTag extends ElementType = typeof DEFAULT_FOCUS_TRAP_TAG>(props: FocusTrapProps<TTag> & RefProp<typeof FocusTrapFn>): JSX.Element; | ||
export declare let FocusTrap: _internal_ComponentFocusTrap & { | ||
/** @deprecated use `FocusTrapFeatures` instead of `FocusTrap.features` */ | ||
features: typeof FocusTrapFeatures; | ||
}; | ||
export {}; |
@@ -1,1 +0,1 @@ | ||
"use client";import d,{useRef as L}from"react";import{useDisposables as I}from'../../hooks/use-disposables.js';import{useEvent as A}from'../../hooks/use-event.js';import{useEventListener as G}from'../../hooks/use-event-listener.js';import{useIsMounted as g}from'../../hooks/use-is-mounted.js';import{useOnUnmount as W}from'../../hooks/use-on-unmount.js';import{useOwnerDocument as k}from'../../hooks/use-owner.js';import{useServerHandoffComplete as K}from'../../hooks/use-server-handoff-complete.js';import{useSyncRefs as V}from'../../hooks/use-sync-refs.js';import{Direction as M,useTabDirection as q}from'../../hooks/use-tab-direction.js';import{useWatch as y}from'../../hooks/use-watch.js';import{Hidden as F,HiddenFeatures as P}from'../../internal/hidden.js';import{history as R}from'../../utils/active-element-history.js';import{Focus as T,FocusResult as O,focusElement as f,focusIn as m}from'../../utils/focus-management.js';import{match as C}from'../../utils/match.js';import{microTask as _}from'../../utils/micro-task.js';import{forwardRefWithAs as J,render as X}from'../../utils/render.js';function S(t){if(!t)return new Set;if(typeof t=="function")return new Set(t());let o=new Set;for(let e of t.current)e.current instanceof HTMLElement&&o.add(e.current);return o}let z="div";var h=(r=>(r[r.None=1]="None",r[r.InitialFocus=2]="InitialFocus",r[r.TabLock=4]="TabLock",r[r.FocusLock=8]="FocusLock",r[r.RestoreFocus=16]="RestoreFocus",r[r.AutoFocus=32]="AutoFocus",r[r.All=30]="All",r))(h||{});function Q(t,o){let e=L(null),n=V(e,o),{initialFocus:c,initialFocusFallback:p,containers:u,features:r=30,...l}=t;K()||(r=1);let s=k(e);$({ownerDocument:s},!!(r&16));let U=D({ownerDocument:s,container:e,initialFocus:c,initialFocusFallback:p},r);w({ownerDocument:s,container:e,containers:u,previousActiveElement:U},!!(r&8));let b=q(),v=A(a=>{let i=e.current;if(!i)return;(N=>N())(()=>{C(b.current,{[M.Forwards]:()=>{m(i,T.First,{skipElements:[a.relatedTarget,p]})},[M.Backwards]:()=>{m(i,T.Last,{skipElements:[a.relatedTarget,p]})}})})}),B=I(),H=L(!1),x={ref:n,onKeyDown(a){a.key=="Tab"&&(H.current=!0,B.requestAnimationFrame(()=>{H.current=!1}))},onBlur(a){if(!(r&8))return;let i=S(u);e.current instanceof HTMLElement&&i.add(e.current);let E=a.relatedTarget;E instanceof HTMLElement&&E.dataset.headlessuiFocusGuard!=="true"&&(j(i,E)||(H.current?m(e.current,C(b.current,{[M.Forwards]:()=>T.Next,[M.Backwards]:()=>T.Previous})|T.WrapAround,{relativeTo:a.target}):a.target instanceof HTMLElement&&f(a.target)))}};return d.createElement(d.Fragment,null,!!(r&4)&&d.createElement(F,{as:"button",type:"button","data-headlessui-focus-guard":!0,onFocus:v,features:P.Focusable}),X({ourProps:x,theirProps:l,defaultTag:z,name:"FocusTrap"}),!!(r&4)&&d.createElement(F,{as:"button",type:"button","data-headlessui-focus-guard":!0,onFocus:v,features:P.Focusable}))}let Y=J(Q),Le=Object.assign(Y,{features:h});function Z(t=!0){let o=L(R.slice());return y(([e],[n])=>{n===!0&&e===!1&&_(()=>{o.current.splice(0)}),n===!1&&e===!0&&(o.current=R.slice())},[t,R,o]),A(()=>{var e;return(e=o.current.find(n=>n!=null&&n.isConnected))!=null?e:null})}function $({ownerDocument:t},o){let e=Z(o);y(()=>{o||(t==null?void 0:t.activeElement)===(t==null?void 0:t.body)&&f(e())},[o]),W(()=>{o&&f(e())})}function D({ownerDocument:t,container:o,initialFocus:e,initialFocusFallback:n},c){let p=!!(c&2),u=L(null),r=g();return y(()=>{if(!p){n!=null&&n.current&&f(n.current);return}let l=o.current;l&&_(()=>{if(!r.current)return;let s=t==null?void 0:t.activeElement;if(e!=null&&e.current){if((e==null?void 0:e.current)===s){u.current=s;return}}else if(l.contains(s)){u.current=s;return}if(e!=null&&e.current)f(e.current);else{if(c&32){if(m(l,T.First|T.AutoFocus)!==O.Error)return}else if(m(l,T.First)!==O.Error)return;if(n!=null&&n.current&&(f(n.current),(t==null?void 0:t.activeElement)===n.current))return;console.warn("There are no focusable elements inside the <FocusTrap />")}u.current=t==null?void 0:t.activeElement})},[n,p,c]),u}function w({ownerDocument:t,container:o,containers:e,previousActiveElement:n},c){let p=g();G(t==null?void 0:t.defaultView,"focus",u=>{if(!c||!p.current)return;let r=S(e);o.current instanceof HTMLElement&&r.add(o.current);let l=n.current;if(!l)return;let s=u.target;s&&s instanceof HTMLElement?j(r,s)?(n.current=s,f(s)):(u.preventDefault(),u.stopPropagation(),f(l)):f(n.current)},!0)}function j(t,o){for(let e of t)if(e.contains(o))return!0;return!1}export{Le as FocusTrap,h as FocusTrapFeatures}; | ||
"use client";import L,{useRef as M}from"react";import{useDisposables as G}from'../../hooks/use-disposables.js';import{useEvent as A}from'../../hooks/use-event.js';import{useEventListener as W}from'../../hooks/use-event-listener.js';import{useIsMounted as P}from'../../hooks/use-is-mounted.js';import{useIsTopLayer as O}from'../../hooks/use-is-top-layer.js';import{useOnUnmount as K}from'../../hooks/use-on-unmount.js';import{useOwnerDocument as V}from'../../hooks/use-owner.js';import{useServerHandoffComplete as q}from'../../hooks/use-server-handoff-complete.js';import{useSyncRefs as J}from'../../hooks/use-sync-refs.js';import{Direction as H,useTabDirection as X}from'../../hooks/use-tab-direction.js';import{useWatch as y}from'../../hooks/use-watch.js';import{Hidden as C,HiddenFeatures as _}from'../../internal/hidden.js';import{history as b}from'../../utils/active-element-history.js';import{Focus as T,FocusResult as S,focusElement as p,focusIn as E}from'../../utils/focus-management.js';import{match as h}from'../../utils/match.js';import{microTask as j}from'../../utils/micro-task.js';import{forwardRefWithAs as z,render as Q}from'../../utils/render.js';function U(o){if(!o)return new Set;if(typeof o=="function")return new Set(o());let e=new Set;for(let t of o.current)t.current instanceof HTMLElement&&e.add(t.current);return e}let Y="div";var x=(n=>(n[n.None=0]="None",n[n.InitialFocus=1]="InitialFocus",n[n.TabLock=2]="TabLock",n[n.FocusLock=4]="FocusLock",n[n.RestoreFocus=8]="RestoreFocus",n[n.AutoFocus=16]="AutoFocus",n))(x||{});function Z(o,e){let t=M(null),r=J(t,e),{initialFocus:s,initialFocusFallback:a,containers:n,features:u=15,...f}=o;q()||(u=0);let l=V(t);w(u,{ownerDocument:l});let i=ee(u,{ownerDocument:l,container:t,initialFocus:s,initialFocusFallback:a});te(u,{ownerDocument:l,container:t,containers:n,previousActiveElement:i});let R=X(),g=A(c=>{let m=t.current;if(!m)return;(B=>B())(()=>{h(R.current,{[H.Forwards]:()=>{E(m,T.First,{skipElements:[c.relatedTarget,a]})},[H.Backwards]:()=>{E(m,T.Last,{skipElements:[c.relatedTarget,a]})}})})}),v=O(!!(u&2),"focus-trap#tab-lock"),N=G(),F=M(!1),k={ref:r,onKeyDown(c){c.key=="Tab"&&(F.current=!0,N.requestAnimationFrame(()=>{F.current=!1}))},onBlur(c){if(!(u&4))return;let m=U(n);t.current instanceof HTMLElement&&m.add(t.current);let d=c.relatedTarget;d instanceof HTMLElement&&d.dataset.headlessuiFocusGuard!=="true"&&(I(m,d)||(F.current?E(t.current,h(R.current,{[H.Forwards]:()=>T.Next,[H.Backwards]:()=>T.Previous})|T.WrapAround,{relativeTo:c.target}):c.target instanceof HTMLElement&&p(c.target)))}};return L.createElement(L.Fragment,null,v&&L.createElement(C,{as:"button",type:"button","data-headlessui-focus-guard":!0,onFocus:g,features:_.Focusable}),Q({ourProps:k,theirProps:f,defaultTag:Y,name:"FocusTrap"}),v&&L.createElement(C,{as:"button",type:"button","data-headlessui-focus-guard":!0,onFocus:g,features:_.Focusable}))}let $=z(Z),Fe=Object.assign($,{features:x});function D(o=!0){let e=M(b.slice());return y(([t],[r])=>{r===!0&&t===!1&&j(()=>{e.current.splice(0)}),r===!1&&t===!0&&(e.current=b.slice())},[o,b,e]),A(()=>{var t;return(t=e.current.find(r=>r!=null&&r.isConnected))!=null?t:null})}function w(o,{ownerDocument:e}){let t=!!(o&8),r=D(t);y(()=>{t||(e==null?void 0:e.activeElement)===(e==null?void 0:e.body)&&p(r())},[t]),K(()=>{t&&p(r())})}function ee(o,{ownerDocument:e,container:t,initialFocus:r,initialFocusFallback:s}){let a=M(null),n=O(!!(o&1),"focus-trap#initial-focus"),u=P();return y(()=>{if(o===0)return;if(!n){s!=null&&s.current&&p(s.current);return}let f=t.current;f&&j(()=>{if(!u.current)return;let l=e==null?void 0:e.activeElement;if(r!=null&&r.current){if((r==null?void 0:r.current)===l){a.current=l;return}}else if(f.contains(l)){a.current=l;return}if(r!=null&&r.current)p(r.current);else{if(o&16){if(E(f,T.First|T.AutoFocus)!==S.Error)return}else if(E(f,T.First)!==S.Error)return;if(s!=null&&s.current&&(p(s.current),(e==null?void 0:e.activeElement)===s.current))return;console.warn("There are no focusable elements inside the <FocusTrap />")}a.current=e==null?void 0:e.activeElement})},[s,n,o]),a}function te(o,{ownerDocument:e,container:t,containers:r,previousActiveElement:s}){let a=P(),n=!!(o&4);W(e==null?void 0:e.defaultView,"focus",u=>{if(!n||!a.current)return;let f=U(r);t.current instanceof HTMLElement&&f.add(t.current);let l=s.current;if(!l)return;let i=u.target;i&&i instanceof HTMLElement?I(f,i)?(s.current=i,p(i)):(u.preventDefault(),u.stopPropagation(),p(l)):p(s.current)},!0)}function I(o,e){for(let t of o)if(t.contains(e))return!0;return!1}export{Fe as FocusTrap,x as FocusTrapFeatures}; |
@@ -27,2 +27,3 @@ import React, { type ElementType, type Ref } from 'react'; | ||
multiple?: boolean; | ||
__demoMode?: boolean; | ||
}>; | ||
@@ -55,3 +56,5 @@ declare function ListboxFn<TTag extends ElementType = typeof DEFAULT_LISTBOX_TAG, TType = string, TActualType = TType extends (infer U)[] ? U : TType>(props: ListboxProps<TTag, TType, TActualType>, ref: Ref<HTMLElement>): React.JSX.Element; | ||
anchor?: AnchorPropsWithSelection; | ||
portal?: boolean; | ||
modal?: boolean; | ||
transition?: boolean; | ||
} & PropsForFeatures<typeof OptionsRenderFeatures>>; | ||
@@ -109,8 +112,13 @@ declare function OptionsFn<TTag extends ElementType = typeof DEFAULT_OPTIONS_TAG>(props: ListboxOptionsProps<TTag>, ref: Ref<HTMLElement>): React.JSX.Element; | ||
export declare let Listbox: _internal_ComponentListbox & { | ||
/** @deprecated use `<ListboxButton>` instead of `<Listbox.Button>` */ | ||
Button: _internal_ComponentListboxButton; | ||
/** @deprecated use `<Label>` instead of `<Listbox.Label>` */ | ||
Label: _internal_ComponentListboxLabel; | ||
/** @deprecated use `<ListboxOptions>` instead of `<Listbox.Options>` */ | ||
Options: _internal_ComponentListboxOptions; | ||
/** @deprecated use `<ListboxOption>` instead of `<Listbox.Option>` */ | ||
Option: _internal_ComponentListboxOption; | ||
/** @deprecated use `<ListboxSelectedOption>` instead of `<Listbox.SelectedOption>` */ | ||
SelectedOption: _internal_ComponentListboxSelectedOption; | ||
}; | ||
export {}; |
@@ -1,1 +0,1 @@ | ||
"use client";import{useFocusRing as Se}from"@react-aria/focus";import{useHover as Re}from"@react-aria/interactions";import h,{Fragment as Z,createContext as ee,createRef as Pe,useCallback as pe,useContext as te,useEffect as ue,useMemo as N,useReducer as Ae,useRef as H,useState as Ee}from"react";import{useActivePress as De}from'../../hooks/use-active-press.js';import{useByComparator as he}from'../../hooks/use-by-comparator.js';import{useComputed as Ie}from'../../hooks/use-computed.js';import{useControllable as _e}from'../../hooks/use-controllable.js';import{useDidElementMove as Ce}from'../../hooks/use-did-element-move.js';import{useDisposables as X}from'../../hooks/use-disposables.js';import{useElementSize as Fe}from'../../hooks/use-element-size.js';import{useEvent as x}from'../../hooks/use-event.js';import{useId as oe}from'../../hooks/use-id.js';import{useIsoMorphicEffect as ne}from'../../hooks/use-iso-morphic-effect.js';import{useLatestValue as Me}from'../../hooks/use-latest-value.js';import{useOnDisappear as we}from'../../hooks/use-on-disappear.js';import{useOutsideClick as Be}from'../../hooks/use-outside-click.js';import{useResolveButtonType as Ue}from'../../hooks/use-resolve-button-type.js';import{useSyncRefs as K}from'../../hooks/use-sync-refs.js';import{useTextValue as ke}from'../../hooks/use-text-value.js';import{useTrackedPointer as Ne}from'../../hooks/use-tracked-pointer.js';import{useDisabled as Ge}from'../../internal/disabled.js';import{FloatingProvider as He,useFloatingPanel as Ve,useFloatingPanelProps as Ke,useFloatingReference as je,useFloatingReferenceProps as We}from'../../internal/floating.js';import{FormFields as ze}from'../../internal/form-fields.js';import{useProvidedId as Qe}from'../../internal/id.js';import{Modal as Xe}from'../../internal/modal.js';import{OpenClosedProvider as Je,State as J,useOpenClosed as $e}from'../../internal/open-closed.js';import{isDisabledReactIssue7711 as qe}from'../../utils/bugs.js';import{Focus as O,calculateActiveIndex as ie}from'../../utils/calculate-active-index.js';import{disposables as re}from'../../utils/disposables.js';import{FocusableMode as Ye,isFocusableElement as Ze,sortByDomNode as et}from'../../utils/focus-management.js';import{attemptSubmit as tt}from'../../utils/form.js';import{match as V}from'../../utils/match.js';import{getOwnerDocument as ot}from'../../utils/owner.js';import{RenderFeatures as de,forwardRefWithAs as j,mergeProps as ce,render as W}from'../../utils/render.js';import{useDescribedBy as nt}from'../description/description.js';import{Keys as S}from'../keyboard.js';import{Label as it,useLabelledBy as rt,useLabels as lt}from'../label/label.js';import{Portal as at}from'../portal/portal.js';var st=(o=>(o[o.Open=0]="Open",o[o.Closed=1]="Closed",o))(st||{}),pt=(o=>(o[o.Single=0]="Single",o[o.Multi=1]="Multi",o))(pt||{}),ut=(o=>(o[o.Pointer=0]="Pointer",o[o.Other=1]="Other",o))(ut||{}),dt=(t=>(t[t.OpenListbox=0]="OpenListbox",t[t.CloseListbox=1]="CloseListbox",t[t.GoToOption=2]="GoToOption",t[t.Search=3]="Search",t[t.ClearSearch=4]="ClearSearch",t[t.RegisterOption=5]="RegisterOption",t[t.UnregisterOption=6]="UnregisterOption",t))(dt||{});function le(e,r=o=>o){let o=e.activeOptionIndex!==null?e.options[e.activeOptionIndex]:null,i=et(r(e.options.slice()),d=>d.dataRef.current.domRef.current),n=o?i.indexOf(o):null;return n===-1&&(n=null),{options:i,activeOptionIndex:n}}let ct={[1](e){return e.dataRef.current.disabled||e.listboxState===1?e:{...e,activeOptionIndex:null,listboxState:1}},[0](e){if(e.dataRef.current.disabled||e.listboxState===0)return e;let r=e.activeOptionIndex,{isSelected:o}=e.dataRef.current,i=e.options.findIndex(n=>o(n.dataRef.current.value));return i!==-1&&(r=i),{...e,listboxState:0,activeOptionIndex:r}},[2](e,r){var d,v,t,l,p;if(e.dataRef.current.disabled||e.listboxState===1)return e;let o={...e,searchQuery:"",activationTrigger:(d=r.trigger)!=null?d:1};if(r.focus===O.Nothing)return{...o,activeOptionIndex:null};if(r.focus===O.Specific)return{...o,activeOptionIndex:e.options.findIndex(s=>s.id===r.id)};if(r.focus===O.Previous){let s=e.activeOptionIndex;if(s!==null){let m=e.options[s].dataRef.current.domRef,c=ie(r,{resolveItems:()=>e.options,resolveActiveIndex:()=>e.activeOptionIndex,resolveId:b=>b.id,resolveDisabled:b=>b.dataRef.current.disabled});if(c!==null){let b=e.options[c].dataRef.current.domRef;if(((v=m.current)==null?void 0:v.previousElementSibling)===b.current||((t=b.current)==null?void 0:t.previousElementSibling)===null)return{...o,activeOptionIndex:c}}}}else if(r.focus===O.Next){let s=e.activeOptionIndex;if(s!==null){let m=e.options[s].dataRef.current.domRef,c=ie(r,{resolveItems:()=>e.options,resolveActiveIndex:()=>e.activeOptionIndex,resolveId:b=>b.id,resolveDisabled:b=>b.dataRef.current.disabled});if(c!==null){let b=e.options[c].dataRef.current.domRef;if(((l=m.current)==null?void 0:l.nextElementSibling)===b.current||((p=b.current)==null?void 0:p.nextElementSibling)===null)return{...o,activeOptionIndex:c}}}}let i=le(e),n=ie(r,{resolveItems:()=>i.options,resolveActiveIndex:()=>i.activeOptionIndex,resolveId:s=>s.id,resolveDisabled:s=>s.dataRef.current.disabled});return{...o,...i,activeOptionIndex:n}},[3]:(e,r)=>{if(e.dataRef.current.disabled||e.listboxState===1)return e;let i=e.searchQuery!==""?0:1,n=e.searchQuery+r.value.toLowerCase(),v=(e.activeOptionIndex!==null?e.options.slice(e.activeOptionIndex+i).concat(e.options.slice(0,e.activeOptionIndex+i)):e.options).find(l=>{var p;return!l.dataRef.current.disabled&&((p=l.dataRef.current.textValue)==null?void 0:p.startsWith(n))}),t=v?e.options.indexOf(v):-1;return t===-1||t===e.activeOptionIndex?{...e,searchQuery:n}:{...e,searchQuery:n,activeOptionIndex:t,activationTrigger:1}},[4](e){return e.dataRef.current.disabled||e.listboxState===1||e.searchQuery===""?e:{...e,searchQuery:""}},[5]:(e,r)=>{let o={id:r.id,dataRef:r.dataRef},i=le(e,n=>[...n,o]);return e.activeOptionIndex===null&&e.dataRef.current.isSelected(r.dataRef.current.value)&&(i.activeOptionIndex=i.options.indexOf(o)),{...e,...i}},[6]:(e,r)=>{let o=le(e,i=>{let n=i.findIndex(d=>d.id===r.id);return n!==-1&&i.splice(n,1),i});return{...e,...o,activationTrigger:1}}},ae=ee(null);ae.displayName="ListboxActionsContext";function $(e){let r=te(ae);if(r===null){let o=new Error(`<${e} /> is missing a parent <Listbox /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(o,$),o}return r}let q=ee(null);q.displayName="ListboxDataContext";function z(e){let r=te(q);if(r===null){let o=new Error(`<${e} /> is missing a parent <Listbox /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(o,z),o}return r}function ft(e,r){return V(r.type,ct,e,r)}let bt=Z;function Tt(e,r){var se;let o=Ge(),{value:i,defaultValue:n,form:d,name:v,onChange:t,by:l,invalid:p=!1,disabled:s=o||!1,horizontal:m=!1,multiple:c=!1,...b}=e;const w=m?"horizontal":"vertical";let B=K(r),[A=c?[]:void 0,R]=_e(i,t,n),[D,y]=Ae(ft,{dataRef:Pe(),listboxState:1,options:[],searchQuery:"",activeOptionIndex:null,activationTrigger:1,optionsVisible:!1}),_=H({static:!1,hold:!1}),C=H(null),U=H(null),F=H(new Map),f=he(l),E=pe(T=>V(u.mode,{[1]:()=>A.some(L=>f(L,T)),[0]:()=>f(A,T)}),[A]),u=N(()=>({...D,value:A,disabled:s,invalid:p,mode:c?1:0,orientation:w,compare:f,isSelected:E,optionsPropsRef:_,buttonRef:C,optionsRef:U,listRef:F}),[A,s,p,c,D,F]);ne(()=>{D.dataRef.current=u},[u]),Be([u.buttonRef,u.optionsRef],(T,L)=>{var I;y({type:1}),Ze(L,Ye.Loose)||(T.preventDefault(),(I=u.buttonRef.current)==null||I.focus())},u.listboxState===0);let k=N(()=>({open:u.listboxState===0,disabled:s,invalid:p,value:A}),[u,s,A,p]),g=x(T=>{let L=u.options.find(I=>I.id===T);L&&Y(L.dataRef.current.value)}),G=x(()=>{if(u.activeOptionIndex!==null){let{dataRef:T,id:L}=u.options[u.activeOptionIndex];Y(T.current.value),y({type:2,focus:O.Specific,id:L})}}),Q=x(()=>y({type:0})),a=x(()=>y({type:1})),P=X(),M=x((T,L,I)=>{P.dispose(),P.microTask(()=>T===O.Specific?y({type:2,focus:O.Specific,id:L,trigger:I}):y({type:2,focus:T,trigger:I}))}),be=x((T,L)=>(y({type:5,id:T,dataRef:L}),()=>y({type:6,id:T}))),Y=x(T=>V(u.mode,{[0](){return R==null?void 0:R(T)},[1](){let L=u.value.slice(),I=L.findIndex(Le=>f(Le,T));return I===-1?L.push(T):L.splice(I,1),R==null?void 0:R(L)}})),Te=x(T=>y({type:3,value:T})),xe=x(()=>y({type:4})),me=N(()=>({onChange:Y,registerOption:be,goToOption:M,closeListbox:a,openListbox:Q,selectActiveOption:G,selectOption:g,search:Te,clearSearch:xe}),[]),[Oe,ye]=lt({inherit:!0}),ve={ref:B},ge=pe(()=>R==null?void 0:R(n),[R]);return h.createElement(ye,{value:Oe,props:{htmlFor:(se=u.buttonRef.current)==null?void 0:se.id},slot:{open:u.listboxState===0,disabled:s}},h.createElement(He,null,h.createElement(ae.Provider,{value:me},h.createElement(q.Provider,{value:u},h.createElement(Je,{value:V(u.listboxState,{[0]:J.Open,[1]:J.Closed})},v!=null&&A!=null&&h.createElement(ze,{disabled:s,data:{[v]:A},form:d,onReset:ge}),W({ourProps:ve,theirProps:b,slot:k,defaultTag:bt,name:"Listbox"}))))))}let xt="button";function mt(e,r){var k;let o=z("Listbox.Button"),i=$("Listbox.Button"),n=oe(),d=Qe(),{id:v=d||`headlessui-listbox-button-${n}`,disabled:t=o.disabled||!1,autoFocus:l=!1,...p}=e,s=K(o.buttonRef,r,je()),m=We(),c=X(),b=x(g=>{switch(g.key){case S.Enter:tt(g.currentTarget);break;case S.Space:case S.ArrowDown:g.preventDefault(),i.openListbox(),c.nextFrame(()=>{o.value||i.goToOption(O.First)});break;case S.ArrowUp:g.preventDefault(),i.openListbox(),c.nextFrame(()=>{o.value||i.goToOption(O.Last)});break}}),w=x(g=>{switch(g.key){case S.Space:g.preventDefault();break}}),B=x(g=>{if(qe(g.currentTarget))return g.preventDefault();o.listboxState===0?(i.closeListbox(),c.nextFrame(()=>{var G;return(G=o.buttonRef.current)==null?void 0:G.focus({preventScroll:!0})})):(g.preventDefault(),i.openListbox())}),A=x(g=>g.preventDefault()),R=rt([v]),D=nt(),{isFocusVisible:y,focusProps:_}=Se({autoFocus:l}),{isHovered:C,hoverProps:U}=Re({isDisabled:t}),{pressed:F,pressProps:f}=De({disabled:t}),E=N(()=>({open:o.listboxState===0,active:F||o.listboxState===0,disabled:t,invalid:o.invalid,value:o.value,hover:C,focus:y,autofocus:l}),[o.listboxState,o.value,t,C,y,F,o.invalid,l]),u=ce(m(),{ref:s,id:v,type:Ue(e,o.buttonRef),"aria-haspopup":"listbox","aria-controls":(k=o.optionsRef.current)==null?void 0:k.id,"aria-expanded":o.listboxState===0,"aria-labelledby":R,"aria-describedby":D,disabled:t||void 0,autoFocus:l,onKeyDown:b,onKeyUp:w,onKeyPress:A,onClick:B},_,U,f);return W({ourProps:u,theirProps:p,slot:E,defaultTag:xt,name:"Listbox.Button"})}let fe=ee(!1),Ot="div",yt=de.RenderStrategy|de.Static;function vt(e,r){var Q;let o=oe(),{id:i=`headlessui-listbox-options-${o}`,anchor:n,modal:d,...v}=e;n!=null&&d==null?d=!0:d==null&&(d=!1);let t=z("Listbox.Options"),l=$("Listbox.Options"),p=$e(),s=(()=>p!==null?(p&J.Open)===J.Open:t.listboxState===0)();we(t.buttonRef,l.closeListbox,s);let m=H(null);ue(()=>{var P;if(!((P=n==null?void 0:n.to)!=null&&P.includes("selection")))return;if(!s){m.current=null;return}let a=Array.from(t.listRef.current.values());m.current=a.findIndex(M=>(M==null?void 0:M.dataset.selected)===""),m.current===-1&&(m.current=a.findIndex(M=>(M==null?void 0:M.dataset.disabled)===void 0),l.goToOption(O.First))},[s,t.listRef]);let b=Ce(t.buttonRef,t.listboxState!==0)?!1:s,w=(()=>{if(n==null)return;if(t.listRef.current.size<=0)return{...n,inner:void 0};let a=Array.from(t.listRef.current.values());return{...n,inner:{listRef:{current:a},index:m.current}}})(),[B,A]=Ve(w),R=Ke(),D=K(t.optionsRef,r,n?B:null),y=X(),_=X();ue(()=>{var P;let a=t.optionsRef.current;a&&t.listboxState===0&&a!==((P=ot(a))==null?void 0:P.activeElement)&&(a==null||a.focus({preventScroll:!0}))},[t.listboxState,t.optionsRef]);let C=x(a=>{switch(_.dispose(),a.key){case S.Space:if(t.searchQuery!=="")return a.preventDefault(),a.stopPropagation(),l.search(a.key);case S.Enter:if(a.preventDefault(),a.stopPropagation(),t.activeOptionIndex!==null){let{dataRef:P}=t.options[t.activeOptionIndex];l.onChange(P.current.value)}t.mode===0&&(l.closeListbox(),re().nextFrame(()=>{var P;return(P=t.buttonRef.current)==null?void 0:P.focus({preventScroll:!0})}));break;case V(t.orientation,{vertical:S.ArrowDown,horizontal:S.ArrowRight}):return a.preventDefault(),a.stopPropagation(),l.goToOption(O.Next);case V(t.orientation,{vertical:S.ArrowUp,horizontal:S.ArrowLeft}):return a.preventDefault(),a.stopPropagation(),l.goToOption(O.Previous);case S.Home:case S.PageUp:return a.preventDefault(),a.stopPropagation(),l.goToOption(O.First);case S.End:case S.PageDown:return a.preventDefault(),a.stopPropagation(),l.goToOption(O.Last);case S.Escape:return a.preventDefault(),a.stopPropagation(),l.closeListbox(),y.nextFrame(()=>{var P;return(P=t.buttonRef.current)==null?void 0:P.focus({preventScroll:!0})});case S.Tab:a.preventDefault(),a.stopPropagation();break;default:a.key.length===1&&(l.search(a.key),_.setTimeout(()=>l.clearSearch(),350));break}}),U=Ie(()=>{var a;return(a=t.buttonRef.current)==null?void 0:a.id},[t.buttonRef.current]),F=N(()=>({open:t.listboxState===0}),[t]),f=ce(n?R():{},{id:i,ref:D,"aria-activedescendant":t.activeOptionIndex===null||(Q=t.options[t.activeOptionIndex])==null?void 0:Q.id,"aria-multiselectable":t.mode===1?!0:void 0,"aria-labelledby":U,"aria-orientation":t.orientation,onKeyDown:C,role:"listbox",tabIndex:0,style:{...A,"--button-width":Fe(t.buttonRef,!0).width}}),E=d?Xe:n?at:Z,u=d?{enabled:t.listboxState===0}:{},[k,g]=Ee(t.value);t.value!==k&&t.listboxState===0&&t.mode!==1&&g(t.value);let G=x(a=>t.compare(k,a));return h.createElement(E,{...u},h.createElement(q.Provider,{value:t.mode===1?t:{...t,isSelected:G}},W({ourProps:f,theirProps:v,slot:F,defaultTag:Ot,features:yt,visible:b,name:"Listbox.Options"})))}let gt="div";function Lt(e,r){let o=oe(),{id:i=`headlessui-listbox-option-${o}`,disabled:n=!1,value:d,...v}=e,t=te(fe)===!0,l=z("Listbox.Option"),p=$("Listbox.Option"),s=l.activeOptionIndex!==null?l.options[l.activeOptionIndex].id===i:!1,m=l.isSelected(d),c=H(null),b=ke(c),w=Me({disabled:n,value:d,domRef:c,get textValue(){return b()}}),B=K(r,c,f=>{f?l.listRef.current.set(i,f):l.listRef.current.delete(i)});ne(()=>{if(l.listboxState!==0||!s||l.activationTrigger===0)return;let f=re();return f.requestAnimationFrame(()=>{var E,u;(u=(E=c.current)==null?void 0:E.scrollIntoView)==null||u.call(E,{block:"nearest"})}),f.dispose},[c,s,l.listboxState,l.activationTrigger,l.activeOptionIndex]),ne(()=>{if(!t)return p.registerOption(i,w)},[w,i,t]);let A=x(f=>{if(n)return f.preventDefault();p.onChange(d),l.mode===0&&(p.closeListbox(),re().nextFrame(()=>{var E;return(E=l.buttonRef.current)==null?void 0:E.focus({preventScroll:!0})}))}),R=x(()=>{if(n)return p.goToOption(O.Nothing);p.goToOption(O.Specific,i)}),D=Ne(),y=x(f=>{D.update(f),!n&&(s||p.goToOption(O.Specific,i,0))}),_=x(f=>{D.wasMoved(f)&&(n||s||p.goToOption(O.Specific,i,0))}),C=x(f=>{D.wasMoved(f)&&(n||s&&p.goToOption(O.Nothing))}),U=N(()=>({active:s,focus:s,selected:m,disabled:n,selectedOption:m&&t}),[s,m,n,t]),F=t?{}:{id:i,ref:B,role:"option",tabIndex:n===!0?void 0:-1,"aria-disabled":n===!0?!0:void 0,"aria-selected":m,disabled:void 0,onClick:A,onFocus:R,onPointerEnter:y,onMouseEnter:y,onPointerMove:_,onMouseMove:_,onPointerLeave:C,onMouseLeave:C};return!m&&t?null:W({ourProps:F,theirProps:v,slot:U,defaultTag:gt,name:"Listbox.Option"})}let St=Z;function Rt(e,r){let{options:o,placeholder:i,...n}=e,v={ref:K(r)},t=z("ListboxSelectedOption"),l=N(()=>({}),[]),p=t.value===void 0||t.value===null||t.mode===1&&Array.isArray(t.value)&&t.value.length===0;return h.createElement(fe.Provider,{value:!0},W({ourProps:v,theirProps:{...n,children:h.createElement(h.Fragment,null,i&&p?i:o)},slot:l,defaultTag:St,name:"ListboxSelectedOption"}))}let Pt=j(Tt),At=j(mt),Et=it,Dt=j(vt),ht=j(Lt),To=j(Rt),xo=Object.assign(Pt,{Button:At,Label:Et,Options:Dt,Option:ht});export{xo as Listbox,At as ListboxButton,Et as ListboxLabel,ht as ListboxOption,Dt as ListboxOptions,To as ListboxSelectedOption}; | ||
"use client";import{useFocusRing as Ae}from"@react-aria/focus";import{useHover as Re}from"@react-aria/interactions";import R,{Fragment as me,createContext as le,createRef as he,useCallback as ae,useContext as se,useEffect as De,useMemo as w,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 j}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 Y,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 V}from'../../utils/match.js';import{getOwnerDocument as bt}from'../../utils/owner.js';import{RenderFeatures as ye,forwardRefWithAs as z,mergeProps as ve,render as W,useMergeRefsFn as Tt}from'../../utils/render.js';import{useDescribedBy as mt}from'../description/description.js';import{Keys as E}from'../keyboard.js';import{Label as xt,useLabelledBy as Ot,useLabels as yt}from'../label/label.js';import{Portal as vt}from'../portal/portal.js';var gt=(o=>(o[o.Open=0]="Open",o[o.Closed=1]="Closed",o))(gt||{}),Lt=(o=>(o[o.Single=0]="Single",o[o.Multi=1]="Multi",o))(Lt||{}),St=(o=>(o[o.Pointer=0]="Pointer",o[o.Other=1]="Other",o))(St||{}),Et=(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))(Et||{});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 Pt={[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,O,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(((O=P.current)==null?void 0:O.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(),O=(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=O?e.options.indexOf(O):-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 Z(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,Z),o}return i}let ee=le(null);ee.displayName="ListboxDataContext";function Q(e){let i=se(ee);if(i===null){let o=new Error(`<${e} /> is missing a parent <Listbox /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(o,Q),o}return i}function At(e,i){return V(i.type,Pt,e,i)}let Rt=me;function ht(e,i){var Te;let o=Je(),{value:r,defaultValue:a,form:m,name:O,onChange:d,by:p,invalid:n=!1,disabled:u=o||!1,horizontal:P=!1,multiple:t=!1,__demoMode:s=!1,...M}=e;const B=P?"horizontal":"vertical";let h=j(i),D=Be(a),[g=t?[]:void 0,y]=Me(r,d,D),[_,x]=_e(At,{dataRef:he(),listboxState:s?0:1,options:[],searchQuery:"",activeOptionIndex:null,activationTrigger:1,optionsVisible:!1,buttonElement:null,optionsElement:null,__demoMode:s}),k=pe({static:!1,hold:!1}),F=pe(new Map),c=Fe(p),A=ae(b=>V(f.mode,{[1]:()=>g.some(S=>c(S,b)),[0]:()=>c(g,b)}),[g]),f=w(()=>({..._,value:g,disabled:u,invalid:n,mode:t?1:0,orientation:B,compare:c,isSelected:A,optionsPropsRef:k,listRef:F}),[g,u,n,t,_,F]);de(()=>{_.dataRef.current=f},[f]);let N=f.listboxState===0;Ge(N,[f.buttonElement,f.optionsElement],(b,S)=>{var C;x({type:1}),dt(S,pt.Loose)||(b.preventDefault(),(C=f.buttonElement)==null||C.focus())});let L=w(()=>({open:f.listboxState===0,disabled:u,invalid:n,value:g}),[f,u,g,n]),H=T(b=>{let S=f.options.find(C=>C.id===b);S&&K(S.dataRef.current.value)}),te=T(()=>{if(f.activeOptionIndex!==null){let{dataRef:b,id:S}=f.options[f.activeOptionIndex];K(b.current.value),x({type:2,focus:v.Specific,id:S})}}),oe=T(()=>x({type:0})),X=T(()=>x({type:1})),J=xe(),ne=T((b,S,C)=>{J.dispose(),J.microTask(()=>b===v.Specific?x({type:2,focus:v.Specific,id:S,trigger:C}):x({type:2,focus:b,trigger:C}))}),ie=T((b,S)=>(x({type:5,id:b,dataRef:S}),()=>x({type:6,id:b}))),K=T(b=>V(f.mode,{[0](){return y==null?void 0:y(b)},[1](){let S=f.value.slice(),C=S.findIndex(Pe=>c(Pe,b));return C===-1?S.push(b):S.splice(C,1),y==null?void 0:y(S)}})),$=T(b=>x({type:3,value:b})),q=T(()=>x({type:4})),l=T(b=>{x({type:7,element:b})}),I=T(b=>{x({type:8,element:b})}),G=w(()=>({onChange:K,registerOption:ie,goToOption:ne,closeListbox:X,openListbox:oe,selectActiveOption:te,selectOption:H,search:$,clearSearch:q,setButtonElement:l,setOptionsElement:I}),[]),[re,Le]=yt({inherit:!0}),Se={ref:h},Ee=ae(()=>{if(D!==void 0)return y==null?void 0:y(D)},[y,D]);return R.createElement(Le,{value:re,props:{htmlFor:(Te=f.buttonElement)==null?void 0:Te.id},slot:{open:f.listboxState===0,disabled:u}},R.createElement($e,null,R.createElement(be.Provider,{value:G},R.createElement(ee.Provider,{value:f},R.createElement(rt,{value:V(f.listboxState,{[0]:Y.Open,[1]:Y.Closed})},O!=null&&g!=null&&R.createElement(ot,{disabled:u,data:{[O]:g},form:m,onReset:Ee}),W({ourProps:Se,theirProps:M,slot:L,defaultTag:Rt,name:"Listbox"}))))))}let Dt="button";function _t(e,i){var N;let o=Q("Listbox.Button"),r=Z("Listbox.Button"),a=ue(),m=it(),{id:O=m||`headlessui-listbox-button-${a}`,disabled:d=o.disabled||!1,autoFocus:p=!1,...n}=e,u=Tt(),P=j(i,Ze(),r.setButtonElement),t=et(),s=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}}),M=T(L=>{switch(L.key){case E.Space:L.preventDefault();break}}),B=T(L=>{var H;if(at(L.currentTarget))return L.preventDefault();o.listboxState===0?(U(()=>r.closeListbox()),(H=o.buttonElement)==null||H.focus({preventScroll:!0})):(L.preventDefault(),r.openListbox())}),h=T(L=>L.preventDefault()),D=Ot([O]),g=mt(),{isFocusVisible:y,focusProps:_}=Ae({autoFocus:p}),{isHovered:x,hoverProps:k}=Re({isDisabled:d}),{pressed:F,pressProps:c}=Ce({disabled:d}),A=w(()=>({open:o.listboxState===0,active:F||o.listboxState===0,disabled:d,invalid:o.invalid,value:o.value,hover:x,focus:y,autofocus:p}),[o.listboxState,o.value,d,x,y,F,o.invalid,p]),f=ve(t(),{ref:P,id:O,type:Ke(e,o.buttonElement),"aria-haspopup":"listbox","aria-controls":(N=o.optionsElement)==null?void 0:N.id,"aria-expanded":o.listboxState===0,"aria-labelledby":D,"aria-describedby":g,disabled:d||void 0,autoFocus:p,onKeyDown:s,onKeyUp:M,onKeyPress:h,onClick:B},_,k,c);return W({mergeRefs:u,ourProps:f,theirProps:n,slot:A,defaultTag:Dt,name:"Listbox.Button"})}let ge=le(!1),It="div",Ct=ye.RenderStrategy|ye.Static;function Ft(e,i){var $,q;let o=ue(),{id:r=`headlessui-listbox-options-${o}`,anchor:a,portal:m=!1,modal:O=!0,transition:d=!1,...p}=e,n=tt(a),[u,P]=Ie(null);n&&(m=!0);let t=Q("Listbox.Options"),s=Z("Listbox.Options"),M=Ve(t.optionsElement),B=lt(),[h,D]=Xe(d,u,B!==null?(B&Y.Open)===Y.Open:t.listboxState===0);He(h,t.buttonElement,s.closeListbox);let g=t.__demoMode?!1:O&&t.listboxState===0;je(g,M);let y=t.__demoMode?!1:O&&t.listboxState===0;Ue(y,{allowed:ae(()=>[t.buttonElement,t.optionsElement],[t.buttonElement,t.optionsElement])});let _=t.listboxState!==0,k=we(_,t.buttonElement)?!1:h,F=h&&t.listboxState===1,c=nt(F,t.value),A=T(l=>t.compare(c,l)),f=w(()=>{var I;if(n==null||!((I=n==null?void 0:n.to)!=null&&I.includes("selection")))return null;let l=t.options.findIndex(G=>A(G.dataRef.current.value));return l===-1&&(l=0),l},[n,t.options]),N=(()=>{if(n==null)return;if(f===null)return{...n,inner:void 0};let l=Array.from(t.listRef.current.values());return{...n,inner:{listRef:{current:l},index:f}}})(),[L,H]=qe(N),te=Ye(),oe=j(i,n?L:null,s.setOptionsElement,P),X=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 J=T(l=>{var I,G;switch(X.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 V(t.orientation,{vertical:E.ArrowDown,horizontal:E.ArrowRight}):return l.preventDefault(),l.stopPropagation(),s.goToOption(v.Next);case V(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()),(G=t.buttonElement)==null||G.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),X.setTimeout(()=>s.clearSearch(),350));break}}),ne=($=t.buttonElement)==null?void 0:$.id,ie=w(()=>({open:t.listboxState===0}),[t.listboxState]),K=ve(n?te():{},{id:r,ref:oe,"aria-activedescendant":t.activeOptionIndex===null||(q=t.options[t.activeOptionIndex])==null?void 0:q.id,"aria-multiselectable":t.mode===1?!0:void 0,"aria-labelledby":ne,"aria-orientation":t.orientation,onKeyDown:J,role:"listbox",tabIndex:t.listboxState===0?0:void 0,style:{...p.style,...H,"--button-width":ke(t.buttonElement,!0).width},...Qe(D)});return R.createElement(vt,{enabled:m?e.static||h:!1},R.createElement(ee.Provider,{value:t.mode===1?t:{...t,isSelected:A}},W({ourProps:K,theirProps:p,slot:ie,defaultTag:It,features:Ct,visible:k,name:"Listbox.Options"})))}let Mt="div";function Bt(e,i){let o=ue(),{id:r=`headlessui-listbox-option-${o}`,disabled:a=!1,value:m,...O}=e,d=se(ge)===!0,p=Q("Listbox.Option"),n=Z("Listbox.Option"),u=p.activeOptionIndex!==null?p.options[p.activeOptionIndex].id===r:!1,P=p.isSelected(m),t=pe(null),s=ze(t),M=Ne({disabled:a,value:m,domRef:t,get textValue(){return s()}}),B=j(i,t,c=>{c?p.listRef.current.set(r,c):p.listRef.current.delete(r)});de(()=>{if(!p.__demoMode&&p.listboxState===0&&u&&p.activationTrigger!==0)return st().requestAnimationFrame(()=>{var c,A;(A=(c=t.current)==null?void 0:c.scrollIntoView)==null||A.call(c,{block:"nearest"})})},[t,u,p.__demoMode,p.listboxState,p.activationTrigger,p.activeOptionIndex]),de(()=>{if(!d)return n.registerOption(r,M)},[M,r,d]);let h=T(c=>{var A;if(a)return c.preventDefault();n.onChange(m),p.mode===0&&(U(()=>n.closeListbox()),(A=p.buttonElement)==null||A.focus({preventScroll:!0}))}),D=T(()=>{if(a)return n.goToOption(v.Nothing);n.goToOption(v.Specific,r)}),g=We(),y=T(c=>{g.update(c),!a&&(u||n.goToOption(v.Specific,r,0))}),_=T(c=>{g.wasMoved(c)&&(a||u||n.goToOption(v.Specific,r,0))}),x=T(c=>{g.wasMoved(c)&&(a||u&&n.goToOption(v.Nothing))}),k=w(()=>({active:u,focus:u,selected:P,disabled:a,selectedOption:P&&d}),[u,P,a,d]),F=d?{}:{id:r,ref:B,role:"option",tabIndex:a===!0?void 0:-1,"aria-disabled":a===!0?!0:void 0,"aria-selected":P,disabled:void 0,onClick:h,onFocus:D,onPointerEnter:y,onMouseEnter:y,onPointerMove:_,onMouseMove:_,onPointerLeave:x,onMouseLeave:x};return!P&&d?null:W({ourProps:F,theirProps:O,slot:k,defaultTag:Mt,name:"Listbox.Option"})}let wt=me;function kt(e,i){let{options:o,placeholder:r,...a}=e,O={ref:j(i)},d=Q("ListboxSelectedOption"),p=w(()=>({}),[]),n=d.value===void 0||d.value===null||d.mode===1&&Array.isArray(d.value)&&d.value.length===0;return R.createElement(ge.Provider,{value:!0},W({ourProps:O,theirProps:{...a,children:R.createElement(R.Fragment,null,r&&n?r:o)},slot:p,defaultTag:wt,name:"ListboxSelectedOption"}))}let Ut=z(ht),Nt=z(_t),Ht=xt,Gt=z(Ft),Vt=z(Bt),Kt=z(kt),Mo=Object.assign(Ut,{Button:Nt,Label:Ht,Options:Gt,Option:Vt,SelectedOption:Kt});export{Mo as Listbox,Nt as ListboxButton,Ht as ListboxLabel,Vt as ListboxOption,Gt as ListboxOptions,Kt as ListboxSelectedOption}; |
@@ -39,7 +39,9 @@ import React, { type ElementType, type Ref } from 'react'; | ||
anchor?: AnchorProps; | ||
portal?: boolean; | ||
modal?: boolean; | ||
transition?: boolean; | ||
static?: boolean; | ||
unmount?: boolean; | ||
}>; | ||
declare function ItemsFn<TTag extends ElementType = typeof DEFAULT_ITEMS_TAG>(props: MenuItemsProps<TTag>, ref: Ref<HTMLDivElement>): React.JSX.Element; | ||
declare function ItemsFn<TTag extends ElementType = typeof DEFAULT_ITEMS_TAG>(props: MenuItemsProps<TTag>, ref: Ref<HTMLElement>): React.JSX.Element; | ||
declare let DEFAULT_ITEM_TAG: React.ExoticComponent<{ | ||
@@ -103,9 +105,15 @@ children?: React.ReactNode; | ||
export declare let Menu: _internal_ComponentMenu & { | ||
/** @deprecated use `<MenuButton>` instead of `<Menu.Button>` */ | ||
Button: _internal_ComponentMenuButton; | ||
/** @deprecated use `<MenuItems>` instead of `<Menu.Items>` */ | ||
Items: _internal_ComponentMenuItems; | ||
/** @deprecated use `<MenuItem>` instead of `<Menu.Item>` */ | ||
Item: _internal_ComponentMenuItem; | ||
/** @deprecated use `<MenuSection>` instead of `<Menu.Section>` */ | ||
Section: _internal_ComponentMenuSection; | ||
/** @deprecated use `<MenuHeading>` instead of `<Menu.Heading>` */ | ||
Heading: _internal_ComponentMenuHeading; | ||
/** @deprecated use `<MenuSeparator>` instead of `<Menu.Separator>` */ | ||
Separator: _internal_ComponentMenuSeparator; | ||
}; | ||
export {}; |
@@ -1,1 +0,1 @@ | ||
"use client";import{useFocusRing as re}from"@react-aria/focus";import{useHover as oe}from"@react-aria/interactions";import E,{Fragment as W,createContext as ae,createRef as X,useContext as ie,useEffect as se,useMemo as U,useReducer as le,useRef as $}from"react";import{useActivePress as ue}from'../../hooks/use-active-press.js';import{useDidElementMove as pe}from'../../hooks/use-did-element-move.js';import{useDisposables as q}from'../../hooks/use-disposables.js';import{useElementSize as de}from'../../hooks/use-element-size.js';import{useEvent as M}from'../../hooks/use-event.js';import{useId as H}from'../../hooks/use-id.js';import{useIsoMorphicEffect as N}from'../../hooks/use-iso-morphic-effect.js';import{useOnDisappear as me}from'../../hooks/use-on-disappear.js';import{useOutsideClick as ce}from'../../hooks/use-outside-click.js';import{useOwnerDocument as fe}from'../../hooks/use-owner.js';import{useResolveButtonType as Te}from'../../hooks/use-resolve-button-type.js';import{useSyncRefs as B}from'../../hooks/use-sync-refs.js';import{useTextValue as ye}from'../../hooks/use-text-value.js';import{useTrackedPointer as ge}from'../../hooks/use-tracked-pointer.js';import{useTreeWalker as Ie}from'../../hooks/use-tree-walker.js';import{FloatingProvider as Me,useFloatingPanel as Pe,useFloatingPanelProps as Ae,useFloatingReference as Se,useFloatingReferenceProps as be}from'../../internal/floating.js';import{Modal as Ee,ModalFeatures as Re}from'../../internal/modal.js';import{OpenClosedProvider as ve,State as k,useOpenClosed as xe}from'../../internal/open-closed.js';import{isDisabledReactIssue7711 as _e}from'../../utils/bugs.js';import{Focus as y,calculateActiveIndex as K}from'../../utils/calculate-active-index.js';import{disposables as j}from'../../utils/disposables.js';import{Focus as z,FocusableMode as De,focusFrom as he,isFocusableElement as Fe,restoreFocusIfNecessary as Y,sortByDomNode as Ce}from'../../utils/focus-management.js';import{match as Z}from'../../utils/match.js';import{RenderFeatures as ee,forwardRefWithAs as R,mergeProps as te,render as v}from'../../utils/render.js';import{useDescriptions as Oe}from'../description/description.js';import{Keys as T}from'../keyboard.js';import{useLabelContext as Le,useLabels as ne}from'../label/label.js';import{Portal as Ge}from'../portal/portal.js';var Ue=(r=>(r[r.Open=0]="Open",r[r.Closed=1]="Closed",r))(Ue||{}),He=(r=>(r[r.Pointer=0]="Pointer",r[r.Other=1]="Other",r))(He||{}),Ne=(e=>(e[e.OpenMenu=0]="OpenMenu",e[e.CloseMenu=1]="CloseMenu",e[e.GoToItem=2]="GoToItem",e[e.Search=3]="Search",e[e.ClearSearch=4]="ClearSearch",e[e.RegisterItem=5]="RegisterItem",e[e.UnregisterItem=6]="UnregisterItem",e))(Ne||{});function Q(t,o=r=>r){let r=t.activeItemIndex!==null?t.items[t.activeItemIndex]:null,i=Ce(o(t.items.slice()),l=>l.dataRef.current.domRef.current),n=r?i.indexOf(r):null;return n===-1&&(n=null),{items:i,activeItemIndex:n}}let Be={[1](t){return t.menuState===1?t:{...t,activeItemIndex:null,menuState:1}},[0](t){return t.menuState===0?t:{...t,__demoMode:!1,menuState:0}},[2]:(t,o)=>{var l,u,e,s,c;if(t.menuState===1)return t;let r={...t,searchQuery:"",activationTrigger:(l=o.trigger)!=null?l:1};if(o.focus===y.Nothing)return{...r,activeItemIndex:null};if(o.focus===y.Specific)return{...r,activeItemIndex:t.items.findIndex(d=>d.id===o.id)};if(o.focus===y.Previous){let d=t.activeItemIndex;if(d!==null){let g=t.items[d].dataRef.current.domRef,m=K(o,{resolveItems:()=>t.items,resolveActiveIndex:()=>t.activeItemIndex,resolveId:p=>p.id,resolveDisabled:p=>p.dataRef.current.disabled});if(m!==null){let p=t.items[m].dataRef.current.domRef;if(((u=g.current)==null?void 0:u.previousElementSibling)===p.current||((e=p.current)==null?void 0:e.previousElementSibling)===null)return{...r,activeItemIndex:m}}}}else if(o.focus===y.Next){let d=t.activeItemIndex;if(d!==null){let g=t.items[d].dataRef.current.domRef,m=K(o,{resolveItems:()=>t.items,resolveActiveIndex:()=>t.activeItemIndex,resolveId:p=>p.id,resolveDisabled:p=>p.dataRef.current.disabled});if(m!==null){let p=t.items[m].dataRef.current.domRef;if(((s=g.current)==null?void 0:s.nextElementSibling)===p.current||((c=p.current)==null?void 0:c.nextElementSibling)===null)return{...r,activeItemIndex:m}}}}let i=Q(t),n=K(o,{resolveItems:()=>i.items,resolveActiveIndex:()=>i.activeItemIndex,resolveId:d=>d.id,resolveDisabled:d=>d.dataRef.current.disabled});return{...r,...i,activeItemIndex:n}},[3]:(t,o)=>{let i=t.searchQuery!==""?0:1,n=t.searchQuery+o.value.toLowerCase(),u=(t.activeItemIndex!==null?t.items.slice(t.activeItemIndex+i).concat(t.items.slice(0,t.activeItemIndex+i)):t.items).find(s=>{var c;return((c=s.dataRef.current.textValue)==null?void 0:c.startsWith(n))&&!s.dataRef.current.disabled}),e=u?t.items.indexOf(u):-1;return e===-1||e===t.activeItemIndex?{...t,searchQuery:n}:{...t,searchQuery:n,activeItemIndex:e,activationTrigger:1}},[4](t){return t.searchQuery===""?t:{...t,searchQuery:"",searchActiveItemIndex:null}},[5]:(t,o)=>{let r=Q(t,i=>[...i,{id:o.id,dataRef:o.dataRef}]);return{...t,...r}},[6]:(t,o)=>{let r=Q(t,i=>{let n=i.findIndex(l=>l.id===o.id);return n!==-1&&i.splice(n,1),i});return{...t,...r,activationTrigger:1}}},J=ae(null);J.displayName="MenuContext";function w(t){let o=ie(J);if(o===null){let r=new Error(`<${t} /> is missing a parent <Menu /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(r,w),r}return o}function ke(t,o){return Z(o.type,Be,t,o)}let we=W;function We(t,o){let{__demoMode:r=!1,...i}=t,n=le(ke,{__demoMode:r,menuState:r?0:1,buttonRef:X(),itemsRef:X(),items:[],searchQuery:"",activeItemIndex:null,activationTrigger:1}),[{menuState:l,itemsRef:u,buttonRef:e},s]=n,c=B(o);ce([e,u],(p,A)=>{var P;s({type:1}),Fe(A,De.Loose)||(p.preventDefault(),(P=e.current)==null||P.focus())},l===0);let d=M(()=>{s({type:1})}),g=U(()=>({open:l===0,close:d}),[l,d]),m={ref:c};return E.createElement(Me,null,E.createElement(J.Provider,{value:n},E.createElement(ve,{value:Z(l,{[0]:k.Open,[1]:k.Closed})},v({ourProps:m,theirProps:i,slot:g,defaultTag:we,name:"Menu"}))))}let Ke="button";function je(t,o){var D;let r=H(),{id:i=`headlessui-menu-button-${r}`,disabled:n=!1,autoFocus:l=!1,...u}=t,[e,s]=w("Menu.Button"),c=be(),d=B(e.buttonRef,o,Se()),g=q(),m=M(f=>{switch(f.key){case T.Space:case T.Enter:case T.ArrowDown:f.preventDefault(),f.stopPropagation(),s({type:0}),g.nextFrame(()=>s({type:2,focus:y.First}));break;case T.ArrowUp:f.preventDefault(),f.stopPropagation(),s({type:0}),g.nextFrame(()=>s({type:2,focus:y.Last}));break}}),p=M(f=>{switch(f.key){case T.Space:f.preventDefault();break}}),A=M(f=>{if(_e(f.currentTarget))return f.preventDefault();n||(e.menuState===0?(s({type:1}),g.nextFrame(()=>{var h;return(h=e.buttonRef.current)==null?void 0:h.focus({preventScroll:!0})})):(f.preventDefault(),s({type:0})))}),{isFocusVisible:P,focusProps:S}=re({autoFocus:l}),{isHovered:x,hoverProps:_}=oe({isDisabled:n}),{pressed:b,pressProps:F}=ue({disabled:n}),C=U(()=>({open:e.menuState===0,active:b||e.menuState===0,disabled:n,hover:x,focus:P,autofocus:l}),[e,x,P,b,n,l]),O=te(c(),{ref:d,id:i,type:Te(t,e.buttonRef),"aria-haspopup":"menu","aria-controls":(D=e.itemsRef.current)==null?void 0:D.id,"aria-expanded":e.menuState===0,disabled:n||void 0,autoFocus:l,onKeyDown:m,onKeyUp:p,onClick:A},S,_,F);return v({ourProps:O,theirProps:u,slot:C,defaultTag:Ke,name:"Menu.Button"})}let Qe="div",Je=ee.RenderStrategy|ee.Static;function Ve(t,o){var h,I;let r=H(),{id:i=`headlessui-menu-items-${r}`,anchor:n,modal:l,...u}=t,[e,s]=w("Menu.Items"),[c,d]=Pe(n),g=Ae(),m=B(e.itemsRef,o,n?c:null),p=fe(e.itemsRef);n!=null&&l==null?l=!0:l==null&&(l=!1);let A=q(),P=xe(),S=(()=>P!==null?(P&k.Open)===k.Open:e.menuState===0)();me(e.buttonRef,()=>s({type:1}),S);let _=pe(e.buttonRef,e.menuState!==0)?!1:S;se(()=>{let a=e.itemsRef.current;a&&e.menuState===0&&a!==(p==null?void 0:p.activeElement)&&a.focus({preventScroll:!0})},[e.menuState,e.itemsRef,p]),Ie({container:e.itemsRef.current,enabled:e.menuState===0,accept(a){return a.getAttribute("role")==="menuitem"?NodeFilter.FILTER_REJECT:a.hasAttribute("role")?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT},walk(a){a.setAttribute("role","none")}});let b=M(a=>{var L,V;switch(A.dispose(),a.key){case T.Space:if(e.searchQuery!=="")return a.preventDefault(),a.stopPropagation(),s({type:3,value:a.key});case T.Enter:if(a.preventDefault(),a.stopPropagation(),s({type:1}),e.activeItemIndex!==null){let{dataRef:G}=e.items[e.activeItemIndex];(V=(L=G.current)==null?void 0:L.domRef.current)==null||V.click()}Y(e.buttonRef.current);break;case T.ArrowDown:return a.preventDefault(),a.stopPropagation(),s({type:2,focus:y.Next});case T.ArrowUp:return a.preventDefault(),a.stopPropagation(),s({type:2,focus:y.Previous});case T.Home:case T.PageUp:return a.preventDefault(),a.stopPropagation(),s({type:2,focus:y.First});case T.End:case T.PageDown:return a.preventDefault(),a.stopPropagation(),s({type:2,focus:y.Last});case T.Escape:a.preventDefault(),a.stopPropagation(),s({type:1}),j().nextFrame(()=>{var G;return(G=e.buttonRef.current)==null?void 0:G.focus({preventScroll:!0})});break;case T.Tab:a.preventDefault(),a.stopPropagation(),s({type:1}),j().microTask(()=>{he(e.buttonRef.current,a.shiftKey?z.Previous:z.Next)});break;default:a.key.length===1&&(s({type:3,value:a.key}),A.setTimeout(()=>s({type:4}),350));break}}),F=M(a=>{switch(a.key){case T.Space:a.preventDefault();break}}),C=U(()=>({open:e.menuState===0}),[e]),O=te(n?g():{},{"aria-activedescendant":e.activeItemIndex===null||(h=e.items[e.activeItemIndex])==null?void 0:h.id,"aria-labelledby":(I=e.buttonRef.current)==null?void 0:I.id,id:i,onKeyDown:b,onKeyUp:F,role:"menu",tabIndex:0,ref:m,style:{...d,"--button-width":de(e.buttonRef,!0).width}}),D=l?Ee:n?Ge:W,f=l?{features:Re.ScrollLock,enabled:e.menuState===0}:{};return E.createElement(D,{...f},v({ourProps:O,theirProps:u,slot:C,defaultTag:Qe,features:Je,visible:_,name:"Menu.Items"}))}let Xe=W;function $e(t,o){let r=H(),{id:i=`headlessui-menu-item-${r}`,disabled:n=!1,...l}=t,[u,e]=w("Menu.Item"),s=u.activeItemIndex!==null?u.items[u.activeItemIndex].id===i:!1,c=$(null),d=B(o,c);N(()=>{if(u.__demoMode||u.menuState!==0||!s||u.activationTrigger===0)return;let I=j();return I.requestAnimationFrame(()=>{var a,L;(L=(a=c.current)==null?void 0:a.scrollIntoView)==null||L.call(a,{block:"nearest"})}),I.dispose},[u.__demoMode,c,s,u.menuState,u.activationTrigger,u.activeItemIndex]);let g=ye(c),m=$({disabled:n,domRef:c,get textValue(){return g()}});N(()=>{m.current.disabled=n},[m,n]),N(()=>(e({type:5,id:i,dataRef:m}),()=>e({type:6,id:i})),[m,i]);let p=M(()=>{e({type:1})}),A=M(I=>{if(n)return I.preventDefault();e({type:1}),Y(u.buttonRef.current)}),P=M(()=>{if(n)return e({type:2,focus:y.Nothing});e({type:2,focus:y.Specific,id:i})}),S=ge(),x=M(I=>{S.update(I),!n&&(s||e({type:2,focus:y.Specific,id:i,trigger:0}))}),_=M(I=>{S.wasMoved(I)&&(n||s||e({type:2,focus:y.Specific,id:i,trigger:0}))}),b=M(I=>{S.wasMoved(I)&&(n||s&&e({type:2,focus:y.Nothing}))}),[F,C]=ne(),[O,D]=Oe(),f=U(()=>({active:s,focus:s,disabled:n,close:p}),[s,n,p]);return E.createElement(C,null,E.createElement(D,null,v({ourProps:{id:i,ref:d,role:"menuitem",tabIndex:n===!0?void 0:-1,"aria-disabled":n===!0?!0:void 0,"aria-labelledby":F,"aria-describedby":O,disabled:void 0,onClick:A,onFocus:P,onPointerEnter:x,onMouseEnter:x,onPointerMove:_,onMouseMove:_,onPointerLeave:b,onMouseLeave:b},theirProps:l,slot:f,defaultTag:Xe,name:"Menu.Item"})))}let qe="div";function ze(t,o){let[r,i]=ne();return E.createElement(i,null,v({ourProps:{ref:o,"aria-labelledby":r,role:"group"},theirProps:t,slot:{},defaultTag:qe,name:"Menu.Section"}))}let Ye="header";function Ze(t,o){let r=H(),{id:i=`headlessui-menu-heading-${r}`,...n}=t,l=Le();N(()=>l.register(i),[i,l.register]);let u={id:i,ref:o,role:"presentation",...l.props};return v({ourProps:u,theirProps:n,slot:{},defaultTag:Ye,name:"Menu.Heading"})}let et="div";function tt(t,o){return v({ourProps:{ref:o,role:"separator"},theirProps:t,slot:{},defaultTag:et,name:"Menu.Separator"})}let nt=R(We),rt=R(je),ot=R(Ve),at=R($e),it=R(ze),st=R(Ze),lt=R(tt),kt=Object.assign(nt,{Button:rt,Items:ot,Item:at,Section:it,Heading:st,Separator:lt});export{kt as Menu,rt as MenuButton,st as MenuHeading,at as MenuItem,ot as MenuItems,it as MenuSection,lt as MenuSeparator}; | ||
"use client";import{useFocusRing as ue}from"@react-aria/focus";import{useHover as pe}from"@react-aria/interactions";import R,{Fragment as q,createContext as me,useCallback as de,useContext as ce,useEffect as fe,useMemo as H,useReducer as Te,useRef as z,useState as ye}from"react";import{flushSync as O}from"react-dom";import{useActivePress as Ie}from'../../hooks/use-active-press.js';import{useDidElementMove as ge}from'../../hooks/use-did-element-move.js';import{useDisposables as Ee}from'../../hooks/use-disposables.js';import{useElementSize as Me}from'../../hooks/use-element-size.js';import{useEvent as E}from'../../hooks/use-event.js';import{useId as U}from'../../hooks/use-id.js';import{useInertOthers as Se}from'../../hooks/use-inert-others.js';import{useIsoMorphicEffect as B}from'../../hooks/use-iso-morphic-effect.js';import{useOnDisappear as Ae}from'../../hooks/use-on-disappear.js';import{useOutsideClick as Pe}from'../../hooks/use-outside-click.js';import{useOwnerDocument as be}from'../../hooks/use-owner.js';import{useResolveButtonType as ve}from'../../hooks/use-resolve-button-type.js';import{useScrollLock as xe}from'../../hooks/use-scroll-lock.js';import{useSyncRefs as N}from'../../hooks/use-sync-refs.js';import{useTextValue as Re}from'../../hooks/use-text-value.js';import{useTrackedPointer as _e}from'../../hooks/use-tracked-pointer.js';import{transitionDataAttributes as De,useTransition as he}from'../../hooks/use-transition.js';import{useTreeWalker as Ce}from'../../hooks/use-tree-walker.js';import{FloatingProvider as Fe,useFloatingPanel as Le,useFloatingPanelProps as Oe,useFloatingReference as Ge,useFloatingReferenceProps as He,useResolvedAnchor as Ue}from'../../internal/floating.js';import{OpenClosedProvider as Be,State as k,useOpenClosed as Ne}from'../../internal/open-closed.js';import{isDisabledReactIssue7711 as ke}from'../../utils/bugs.js';import{Focus as I,calculateActiveIndex as K}from'../../utils/calculate-active-index.js';import{disposables as we}from'../../utils/disposables.js';import{Focus as Y,FocusableMode as Ke,focusFrom as We,isFocusableElement as je,restoreFocusIfNecessary as Z,sortByDomNode as Qe}from'../../utils/focus-management.js';import{match as ee}from'../../utils/match.js';import{RenderFeatures as te,forwardRefWithAs as _,mergeProps as ne,render as D,useMergeRefsFn as Je}from'../../utils/render.js';import{useDescriptions as Ve}from'../description/description.js';import{Keys as y}from'../keyboard.js';import{useLabelContext as Xe,useLabels as re}from'../label/label.js';import{Portal as $e}from'../portal/portal.js';var qe=(r=>(r[r.Open=0]="Open",r[r.Closed=1]="Closed",r))(qe||{}),ze=(r=>(r[r.Pointer=0]="Pointer",r[r.Other=1]="Other",r))(ze||{}),Ye=(a=>(a[a.OpenMenu=0]="OpenMenu",a[a.CloseMenu=1]="CloseMenu",a[a.GoToItem=2]="GoToItem",a[a.Search=3]="Search",a[a.ClearSearch=4]="ClearSearch",a[a.RegisterItem=5]="RegisterItem",a[a.UnregisterItem=6]="UnregisterItem",a[a.SetButtonElement=7]="SetButtonElement",a[a.SetItemsElement=8]="SetItemsElement",a))(Ye||{});function W(e,n=r=>r){let r=e.activeItemIndex!==null?e.items[e.activeItemIndex]:null,i=Qe(n(e.items.slice()),p=>p.dataRef.current.domRef.current),o=r?i.indexOf(r):null;return o===-1&&(o=null),{items:i,activeItemIndex:o}}let Ze={[1](e){return e.menuState===1?e:{...e,activeItemIndex:null,menuState:1}},[0](e){return e.menuState===0?e:{...e,__demoMode:!1,menuState:0}},[2]:(e,n)=>{var p,m,s,u,a;if(e.menuState===1)return e;let r={...e,searchQuery:"",activationTrigger:(p=n.trigger)!=null?p:1,__demoMode:!1};if(n.focus===I.Nothing)return{...r,activeItemIndex:null};if(n.focus===I.Specific)return{...r,activeItemIndex:e.items.findIndex(t=>t.id===n.id)};if(n.focus===I.Previous){let t=e.activeItemIndex;if(t!==null){let d=e.items[t].dataRef.current.domRef,f=K(n,{resolveItems:()=>e.items,resolveActiveIndex:()=>e.activeItemIndex,resolveId:c=>c.id,resolveDisabled:c=>c.dataRef.current.disabled});if(f!==null){let c=e.items[f].dataRef.current.domRef;if(((m=d.current)==null?void 0:m.previousElementSibling)===c.current||((s=c.current)==null?void 0:s.previousElementSibling)===null)return{...r,activeItemIndex:f}}}}else if(n.focus===I.Next){let t=e.activeItemIndex;if(t!==null){let d=e.items[t].dataRef.current.domRef,f=K(n,{resolveItems:()=>e.items,resolveActiveIndex:()=>e.activeItemIndex,resolveId:c=>c.id,resolveDisabled:c=>c.dataRef.current.disabled});if(f!==null){let c=e.items[f].dataRef.current.domRef;if(((u=d.current)==null?void 0:u.nextElementSibling)===c.current||((a=c.current)==null?void 0:a.nextElementSibling)===null)return{...r,activeItemIndex:f}}}}let i=W(e),o=K(n,{resolveItems:()=>i.items,resolveActiveIndex:()=>i.activeItemIndex,resolveId:t=>t.id,resolveDisabled:t=>t.dataRef.current.disabled});return{...r,...i,activeItemIndex:o}},[3]:(e,n)=>{let i=e.searchQuery!==""?0:1,o=e.searchQuery+n.value.toLowerCase(),m=(e.activeItemIndex!==null?e.items.slice(e.activeItemIndex+i).concat(e.items.slice(0,e.activeItemIndex+i)):e.items).find(u=>{var a;return((a=u.dataRef.current.textValue)==null?void 0:a.startsWith(o))&&!u.dataRef.current.disabled}),s=m?e.items.indexOf(m):-1;return s===-1||s===e.activeItemIndex?{...e,searchQuery:o}:{...e,searchQuery:o,activeItemIndex:s,activationTrigger:1}},[4](e){return e.searchQuery===""?e:{...e,searchQuery:"",searchActiveItemIndex:null}},[5]:(e,n)=>{let r=W(e,i=>[...i,{id:n.id,dataRef:n.dataRef}]);return{...e,...r}},[6]:(e,n)=>{let r=W(e,i=>{let o=i.findIndex(p=>p.id===n.id);return o!==-1&&i.splice(o,1),i});return{...e,...r,activationTrigger:1}},[7]:(e,n)=>e.buttonElement===n.element?e:{...e,buttonElement:n.element},[8]:(e,n)=>e.itemsElement===n.element?e:{...e,itemsElement:n.element}},j=me(null);j.displayName="MenuContext";function w(e){let n=ce(j);if(n===null){let r=new Error(`<${e} /> is missing a parent <Menu /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(r,w),r}return n}function et(e,n){return ee(n.type,Ze,e,n)}let tt=q;function nt(e,n){let{__demoMode:r=!1,...i}=e,o=Te(et,{__demoMode:r,menuState:r?0:1,buttonElement:null,itemsElement:null,items:[],searchQuery:"",activeItemIndex:null,activationTrigger:1}),[{menuState:p,itemsElement:m,buttonElement:s},u]=o,a=N(n);Pe(p===0,[s,m],(P,S)=>{u({type:1}),je(S,Ke.Loose)||(P.preventDefault(),s==null||s.focus())});let d=E(()=>{u({type:1})}),f=H(()=>({open:p===0,close:d}),[p,d]),c={ref:a};return R.createElement(Fe,null,R.createElement(j.Provider,{value:o},R.createElement(Be,{value:ee(p,{[0]:k.Open,[1]:k.Closed})},D({ourProps:c,theirProps:i,slot:f,defaultTag:tt,name:"Menu"}))))}let rt="button";function ot(e,n){var h;let r=U(),{id:i=`headlessui-menu-button-${r}`,disabled:o=!1,autoFocus:p=!1,...m}=e,[s,u]=w("Menu.Button"),a=He(),t=Je(),d=N(n,Ge(),E(T=>u({type:7,element:T}))),f=E(T=>{switch(T.key){case y.Space:case y.Enter:case y.ArrowDown:T.preventDefault(),T.stopPropagation(),O(()=>u({type:0})),u({type:2,focus:I.First});break;case y.ArrowUp:T.preventDefault(),T.stopPropagation(),O(()=>u({type:0})),u({type:2,focus:I.Last});break}}),c=E(T=>{switch(T.key){case y.Space:T.preventDefault();break}}),P=E(T=>{var G;if(ke(T.currentTarget))return T.preventDefault();o||(s.menuState===0?(O(()=>u({type:1})),(G=s.buttonElement)==null||G.focus({preventScroll:!0})):(T.preventDefault(),u({type:0})))}),{isFocusVisible:S,focusProps:b}=ue({autoFocus:p}),{isHovered:v,hoverProps:M}=pe({isDisabled:o}),{pressed:A,pressProps:x}=Ie({disabled:o}),C=H(()=>({open:s.menuState===0,active:A||s.menuState===0,disabled:o,hover:v,focus:S,autofocus:p}),[s,v,S,A,o,p]),F=ne(a(),{ref:d,id:i,type:ve(e,s.buttonElement),"aria-haspopup":"menu","aria-controls":(h=s.itemsElement)==null?void 0:h.id,"aria-expanded":s.menuState===0,disabled:o||void 0,autoFocus:p,onKeyDown:f,onKeyUp:c,onClick:P},b,M,x);return D({mergeRefs:t,ourProps:F,theirProps:m,slot:C,defaultTag:rt,name:"Menu.Button"})}let at="div",it=te.RenderStrategy|te.Static;function lt(e,n){var Q,J;let r=U(),{id:i=`headlessui-menu-items-${r}`,anchor:o,portal:p=!1,modal:m=!0,transition:s=!1,...u}=e,a=Ue(o),[t,d]=w("Menu.Items"),[f,c]=Le(a),P=Oe(),[S,b]=ye(null),v=N(n,a?f:null,E(l=>d({type:8,element:l})),b),M=be(t.itemsElement);a&&(p=!0);let A=Ne(),[x,C]=he(s,S,A!==null?(A&k.Open)===k.Open:t.menuState===0);Ae(x,t.buttonElement,()=>{d({type:1})});let F=t.__demoMode?!1:m&&t.menuState===0;xe(F,M);let h=t.__demoMode?!1:m&&t.menuState===0;Se(h,{allowed:de(()=>[t.buttonElement,t.itemsElement],[t.buttonElement,t.itemsElement])});let T=t.menuState!==0,g=ge(T,t.buttonElement)?!1:x;fe(()=>{let l=t.itemsElement;l&&t.menuState===0&&l!==(M==null?void 0:M.activeElement)&&l.focus({preventScroll:!0})},[t.menuState,t.itemsElement,M]),Ce(t.menuState===0,{container:t.itemsElement,accept(l){return l.getAttribute("role")==="menuitem"?NodeFilter.FILTER_REJECT:l.hasAttribute("role")?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT},walk(l){l.setAttribute("role","none")}});let L=Ee(),oe=E(l=>{var V,X,$;switch(L.dispose(),l.key){case y.Space:if(t.searchQuery!=="")return l.preventDefault(),l.stopPropagation(),d({type:3,value:l.key});case y.Enter:if(l.preventDefault(),l.stopPropagation(),d({type:1}),t.activeItemIndex!==null){let{dataRef:se}=t.items[t.activeItemIndex];(X=(V=se.current)==null?void 0:V.domRef.current)==null||X.click()}Z(t.buttonElement);break;case y.ArrowDown:return l.preventDefault(),l.stopPropagation(),d({type:2,focus:I.Next});case y.ArrowUp:return l.preventDefault(),l.stopPropagation(),d({type:2,focus:I.Previous});case y.Home:case y.PageUp:return l.preventDefault(),l.stopPropagation(),d({type:2,focus:I.First});case y.End:case y.PageDown:return l.preventDefault(),l.stopPropagation(),d({type:2,focus:I.Last});case y.Escape:l.preventDefault(),l.stopPropagation(),O(()=>d({type:1})),($=t.buttonElement)==null||$.focus({preventScroll:!0});break;case y.Tab:l.preventDefault(),l.stopPropagation(),O(()=>d({type:1})),We(t.buttonElement,l.shiftKey?Y.Previous:Y.Next);break;default:l.key.length===1&&(d({type:3,value:l.key}),L.setTimeout(()=>d({type:4}),350));break}}),ae=E(l=>{switch(l.key){case y.Space:l.preventDefault();break}}),ie=H(()=>({open:t.menuState===0}),[t.menuState]),le=ne(a?P():{},{"aria-activedescendant":t.activeItemIndex===null||(Q=t.items[t.activeItemIndex])==null?void 0:Q.id,"aria-labelledby":(J=t.buttonElement)==null?void 0:J.id,id:i,onKeyDown:oe,onKeyUp:ae,role:"menu",tabIndex:t.menuState===0?0:void 0,ref:v,style:{...u.style,...c,"--button-width":Me(t.buttonElement,!0).width},...De(C)});return R.createElement($e,{enabled:p?e.static||x:!1},D({ourProps:le,theirProps:u,slot:ie,defaultTag:at,features:it,visible:g,name:"Menu.Items"}))}let st=q;function ut(e,n){let r=U(),{id:i=`headlessui-menu-item-${r}`,disabled:o=!1,...p}=e,[m,s]=w("Menu.Item"),u=m.activeItemIndex!==null?m.items[m.activeItemIndex].id===i:!1,a=z(null),t=N(n,a);B(()=>{if(!m.__demoMode&&m.menuState===0&&u&&m.activationTrigger!==0)return we().requestAnimationFrame(()=>{var g,L;(L=(g=a.current)==null?void 0:g.scrollIntoView)==null||L.call(g,{block:"nearest"})})},[m.__demoMode,a,u,m.menuState,m.activationTrigger,m.activeItemIndex]);let d=Re(a),f=z({disabled:o,domRef:a,get textValue(){return d()}});B(()=>{f.current.disabled=o},[f,o]),B(()=>(s({type:5,id:i,dataRef:f}),()=>s({type:6,id:i})),[f,i]);let c=E(()=>{s({type:1})}),P=E(g=>{if(o)return g.preventDefault();s({type:1}),Z(m.buttonElement)}),S=E(()=>{if(o)return s({type:2,focus:I.Nothing});s({type:2,focus:I.Specific,id:i})}),b=_e(),v=E(g=>{b.update(g),!o&&(u||s({type:2,focus:I.Specific,id:i,trigger:0}))}),M=E(g=>{b.wasMoved(g)&&(o||u||s({type:2,focus:I.Specific,id:i,trigger:0}))}),A=E(g=>{b.wasMoved(g)&&(o||u&&s({type:2,focus:I.Nothing}))}),[x,C]=re(),[F,h]=Ve(),T=H(()=>({active:u,focus:u,disabled:o,close:c}),[u,o,c]);return R.createElement(C,null,R.createElement(h,null,D({ourProps:{id:i,ref:t,role:"menuitem",tabIndex:o===!0?void 0:-1,"aria-disabled":o===!0?!0:void 0,"aria-labelledby":x,"aria-describedby":F,disabled:void 0,onClick:P,onFocus:S,onPointerEnter:v,onMouseEnter:v,onPointerMove:M,onMouseMove:M,onPointerLeave:A,onMouseLeave:A},theirProps:p,slot:T,defaultTag:st,name:"Menu.Item"})))}let pt="div";function mt(e,n){let[r,i]=re();return R.createElement(i,null,D({ourProps:{ref:n,"aria-labelledby":r,role:"group"},theirProps:e,slot:{},defaultTag:pt,name:"Menu.Section"}))}let dt="header";function ct(e,n){let r=U(),{id:i=`headlessui-menu-heading-${r}`,...o}=e,p=Xe();B(()=>p.register(i),[i,p.register]);let m={id:i,ref:n,role:"presentation",...p.props};return D({ourProps:m,theirProps:o,slot:{},defaultTag:dt,name:"Menu.Heading"})}let ft="div";function Tt(e,n){return D({ourProps:{ref:n,role:"separator"},theirProps:e,slot:{},defaultTag:ft,name:"Menu.Separator"})}let yt=_(nt),It=_(ot),gt=_(lt),Et=_(ut),Mt=_(mt),St=_(ct),At=_(Tt),rn=Object.assign(yt,{Button:It,Items:gt,Item:Et,Section:Mt,Heading:St,Separator:At});export{rn as Menu,It as MenuButton,St as MenuHeading,Et as MenuItem,gt as MenuItems,Mt as MenuSection,At as MenuSeparator}; |
@@ -31,10 +31,13 @@ import React, { type ElementType, type MouseEventHandler, type MutableRefObject, type Ref } from 'react'; | ||
declare function ButtonFn<TTag extends ElementType = typeof DEFAULT_BUTTON_TAG>(props: PopoverButtonProps<TTag>, ref: Ref<HTMLButtonElement>): React.JSX.Element; | ||
declare let DEFAULT_OVERLAY_TAG: "div"; | ||
type OverlayRenderPropArg = { | ||
declare let DEFAULT_BACKDROP_TAG: "div"; | ||
type BackdropRenderPropArg = { | ||
open: boolean; | ||
}; | ||
type OverlayPropsWeControl = 'aria-hidden'; | ||
declare let OverlayRenderFeatures: number; | ||
export type PopoverOverlayProps<TTag extends ElementType = typeof DEFAULT_OVERLAY_TAG> = Props<TTag, OverlayRenderPropArg, OverlayPropsWeControl, PropsForFeatures<typeof OverlayRenderFeatures>>; | ||
declare function OverlayFn<TTag extends ElementType = typeof DEFAULT_OVERLAY_TAG>(props: PopoverOverlayProps<TTag>, ref: Ref<HTMLDivElement>): React.ReactElement<any, string | React.JSXElementConstructor<any>> | null; | ||
type BackdropPropsWeControl = 'aria-hidden'; | ||
declare let BackdropRenderFeatures: number; | ||
export type PopoverBackdropProps<TTag extends ElementType = typeof DEFAULT_BACKDROP_TAG> = Props<TTag, BackdropRenderPropArg, BackdropPropsWeControl, { | ||
transition?: boolean; | ||
} & PropsForFeatures<typeof BackdropRenderFeatures>>; | ||
export type PopoverOverlayProps<TTag extends ElementType = typeof DEFAULT_BACKDROP_TAG> = PopoverBackdropProps<TTag>; | ||
declare function BackdropFn<TTag extends ElementType = typeof DEFAULT_BACKDROP_TAG>(props: PopoverBackdropProps<TTag>, ref: Ref<HTMLElement>): React.ReactElement<any, string | React.JSXElementConstructor<any>> | null; | ||
declare let DEFAULT_PANEL_TAG: "div"; | ||
@@ -49,7 +52,9 @@ type PanelRenderPropArg = { | ||
anchor?: AnchorProps; | ||
portal?: boolean; | ||
modal?: boolean; | ||
transition?: boolean; | ||
static?: boolean; | ||
unmount?: boolean; | ||
}>; | ||
declare function PanelFn<TTag extends ElementType = typeof DEFAULT_PANEL_TAG>(props: PopoverPanelProps<TTag>, ref: Ref<HTMLDivElement>): React.JSX.Element; | ||
declare function PanelFn<TTag extends ElementType = typeof DEFAULT_PANEL_TAG>(props: PopoverPanelProps<TTag>, ref: Ref<HTMLElement>): React.JSX.Element; | ||
declare let DEFAULT_GROUP_TAG: "div"; | ||
@@ -66,4 +71,4 @@ type GroupRenderPropArg = {}; | ||
} | ||
export interface _internal_ComponentPopoverOverlay extends HasDisplayName { | ||
<TTag extends ElementType = typeof DEFAULT_OVERLAY_TAG>(props: PopoverOverlayProps<TTag> & RefProp<typeof OverlayFn>): JSX.Element; | ||
export interface _internal_ComponentPopoverBackdrop extends HasDisplayName { | ||
<TTag extends ElementType = typeof DEFAULT_BACKDROP_TAG>(props: PopoverBackdropProps<TTag> & RefProp<typeof BackdropFn>): JSX.Element; | ||
} | ||
@@ -77,11 +82,19 @@ export interface _internal_ComponentPopoverPanel extends HasDisplayName { | ||
export declare let PopoverButton: _internal_ComponentPopoverButton; | ||
export declare let PopoverOverlay: _internal_ComponentPopoverOverlay; | ||
/** @deprecated use `<PopoverBackdrop>` instead of `<PopoverOverlay>` */ | ||
export declare let PopoverOverlay: _internal_ComponentPopoverBackdrop; | ||
export declare let PopoverBackdrop: _internal_ComponentPopoverBackdrop; | ||
export declare let PopoverPanel: _internal_ComponentPopoverPanel; | ||
export declare let PopoverGroup: _internal_ComponentPopoverGroup; | ||
export declare let Popover: _internal_ComponentPopover & { | ||
/** @deprecated use `<PopoverButton>` instead of `<Popover.Button>` */ | ||
Button: _internal_ComponentPopoverButton; | ||
Overlay: _internal_ComponentPopoverOverlay; | ||
/** @deprecated use `<PopoverBackdrop>` instead of `<Popover.Backdrop>` */ | ||
Backdrop: _internal_ComponentPopoverBackdrop; | ||
/** @deprecated use `<PopoverOverlay>` instead of `<Popover.Overlay>` */ | ||
Overlay: _internal_ComponentPopoverBackdrop; | ||
/** @deprecated use `<PopoverPanel>` instead of `<Popover.Panel>` */ | ||
Panel: _internal_ComponentPopoverPanel; | ||
/** @deprecated use `<PopoverGroup>` instead of `<Popover.Group>` */ | ||
Group: _internal_ComponentPopoverGroup; | ||
}; | ||
export {}; |
@@ -1,1 +0,1 @@ | ||
"use client";import{useFocusRing as Fe}from"@react-aria/focus";import{useHover as Ce}from"@react-aria/interactions";import b,{Fragment as Me,createContext as Z,createRef as me,useContext as ee,useEffect as te,useMemo as D,useReducer as xe,useRef as q,useState as ye}from"react";import{useActivePress as _e}from'../../hooks/use-active-press.js';import{useElementSize as Le}from'../../hooks/use-element-size.js';import{useEvent as R}from'../../hooks/use-event.js';import{useEventListener as Ie}from'../../hooks/use-event-listener.js';import{useId as oe}from'../../hooks/use-id.js';import{useIsoMorphicEffect as Be}from'../../hooks/use-iso-morphic-effect.js';import{useLatestValue as Ee}from'../../hooks/use-latest-value.js';import{useOnDisappear as he}from'../../hooks/use-on-disappear.js';import{useOutsideClick as De}from'../../hooks/use-outside-click.js';import{useOwnerDocument as pe}from'../../hooks/use-owner.js';import{useResolveButtonType as Ge}from'../../hooks/use-resolve-button-type.js';import{useMainTreeNode as He,useRootContainers as Ne}from'../../hooks/use-root-containers.js';import{optionalRef as Ue,useSyncRefs as J}from'../../hooks/use-sync-refs.js';import{Direction as U,useTabDirection as be}from'../../hooks/use-tab-direction.js';import{CloseProvider as ke}from'../../internal/close-provider.js';import{FloatingProvider as we,useFloatingPanel as We,useFloatingPanelProps as Ve,useFloatingReference as Ke}from'../../internal/floating.js';import{Hidden as se,HiddenFeatures as ue}from'../../internal/hidden.js';import{Modal as ge,ModalFeatures as je}from'../../internal/modal.js';import{OpenClosedProvider as $e,State as X,useOpenClosed as Se}from'../../internal/open-closed.js';import{isDisabledReactIssue7711 as Ae}from'../../utils/bugs.js';import{Focus as k,FocusResult as ie,FocusableMode as Je,focusIn as w,getFocusableElements as fe,isFocusableElement as Xe}from'../../utils/focus-management.js';import{match as W}from'../../utils/match.js';import'../../utils/micro-task.js';import{getOwnerDocument as Ye}from'../../utils/owner.js';import{RenderFeatures as re,forwardRefWithAs as z,mergeProps as Pe,render as Q,useMergeRefsFn as qe}from'../../utils/render.js';import{FocusTrapFeatures as ze}from'../focus-trap/focus-trap.js';import{Keys as V}from'../keyboard.js';import{Portal as Re,useNestedPortals as Qe}from'../portal/portal.js';var Ze=(f=>(f[f.Open=0]="Open",f[f.Closed=1]="Closed",f))(Ze||{}),et=(p=>(p[p.TogglePopover=0]="TogglePopover",p[p.ClosePopover=1]="ClosePopover",p[p.SetButton=2]="SetButton",p[p.SetButtonId=3]="SetButtonId",p[p.SetPanel=4]="SetPanel",p[p.SetPanelId=5]="SetPanelId",p))(et||{});let tt={[0]:t=>{let n={...t,popoverState:W(t.popoverState,{[0]:1,[1]:0})};return n.popoverState===0&&(n.__demoMode=!1),n},[1](t){return t.popoverState===1?t:{...t,popoverState: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}}},de=Z(null);de.displayName="PopoverContext";function ne(t){let n=ee(de);if(n===null){let f=new Error(`<${t} /> is missing a parent <Popover /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(f,ne),f}return n}let le=Z(null);le.displayName="PopoverAPIContext";function ce(t){let n=ee(le);if(n===null){let f=new Error(`<${t} /> is missing a parent <Popover /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(f,ce),f}return n}let ve=Z(null);ve.displayName="PopoverGroupContext";function Oe(){return ee(ve)}let ae=Z(null);ae.displayName="PopoverPanelContext";function ot(){return ee(ae)}function rt(t,n){return W(n.type,tt,t,n)}let nt="div";function lt(t,n){var P;let{__demoMode:f=!1,...F}=t,m=q(null),v=J(n,Ue(o=>{m.current=o})),p=q([]),l=xe(rt,{__demoMode:f,popoverState:f?0:1,buttons:p,button:null,buttonId:null,panel:null,panelId:null,beforePanelSentinel:me(),afterPanelSentinel:me()}),[{popoverState:e,button:a,buttonId:g,panel:d,panelId:L,beforePanelSentinel:y,afterPanelSentinel:S},s]=l,i=pe((P=m.current)!=null?P:a),M=D(()=>{if(!a||!d)return!1;for(let A of document.querySelectorAll("body > *"))if(Number(A==null?void 0:A.contains(a))^Number(A==null?void 0:A.contains(d)))return!0;let o=fe(),u=o.indexOf(a),c=(u+o.length-1)%o.length,C=(u+1)%o.length,r=o[c],T=o[C];return!d.contains(r)&&!d.contains(T)},[a,d]),x=Ee(g),E=Ee(L),I=D(()=>({buttonId:x,panelId:E,close:()=>s({type:1})}),[x,E,s]),O=Oe(),_=O==null?void 0:O.registerPopover,Y=R(()=>{var o;return(o=O==null?void 0:O.isFocusWithinPopoverGroup())!=null?o:(i==null?void 0:i.activeElement)&&((a==null?void 0:a.contains(i.activeElement))||(d==null?void 0:d.contains(i.activeElement)))});te(()=>_==null?void 0:_(I),[_,I]);let[K,j]=Qe(),h=Ne({mainTreeNodeRef:O==null?void 0:O.mainTreeNodeRef,portals:K,defaultContainers:[a,d]});Ie(i==null?void 0:i.defaultView,"focus",o=>{var u,c,C,r;o.target!==window&&o.target instanceof HTMLElement&&e===0&&(Y()||a&&d&&(h.contains(o.target)||(c=(u=y.current)==null?void 0:u.contains)!=null&&c.call(u,o.target)||(r=(C=S.current)==null?void 0:C.contains)!=null&&r.call(C,o.target)||s({type:1})))},!0),De(h.resolveContainers,(o,u)=>{s({type:1}),Xe(u,Je.Loose)||(o.preventDefault(),a==null||a.focus())},e===0);let B=R(o=>{s({type:1});let u=(()=>o?o instanceof HTMLElement?o:"current"in o&&o.current instanceof HTMLElement?o.current:a:a)();u==null||u.focus()}),$=D(()=>({close:B,isPortalled:M}),[B,M]),G=D(()=>({open:e===0,close:B}),[e,B]),H={ref:v};return b.createElement(we,null,b.createElement(ae.Provider,{value:null},b.createElement(de.Provider,{value:l},b.createElement(le.Provider,{value:$},b.createElement(ke,{value:B},b.createElement($e,{value:W(e,{[0]:X.Open,[1]:X.Closed})},b.createElement(j,null,Q({ourProps:H,theirProps:F,slot:G,defaultTag:nt,name:"Popover"}),b.createElement(h.MainTreeNode,null))))))))}let at="button";function pt(t,n){let f=oe(),{id:F=`headlessui-popover-button-${f}`,disabled:m=!1,autoFocus:v=!1,...p}=t,[l,e]=ne("Popover.Button"),{isPortalled:a}=ce("Popover.Button"),g=q(null),d=`headlessui-focus-sentinel-${oe()}`,L=Oe(),y=L==null?void 0:L.closeOthers,s=ot()!==null;te(()=>{if(!s)return e({type:3,buttonId:F}),()=>{e({type:3,buttonId:null})}},[s,F,e]);let[i]=ye(()=>Symbol()),M=J(g,n,Ke(),s?null:r=>{if(r)l.buttons.current.push(i);else{let T=l.buttons.current.indexOf(i);T!==-1&&l.buttons.current.splice(T,1)}l.buttons.current.length>1&&console.warn("You are already using a <Popover.Button /> but only 1 <Popover.Button /> is supported."),r&&e({type:2,button:r})}),x=J(g,n),E=pe(g),I=R(r=>{var T,A,N;if(s){if(l.popoverState===1)return;switch(r.key){case V.Space:case V.Enter:r.preventDefault(),(A=(T=r.target).click)==null||A.call(T),e({type:1}),(N=l.button)==null||N.focus();break}}else switch(r.key){case V.Space:case V.Enter:r.preventDefault(),r.stopPropagation(),l.popoverState===1&&(y==null||y(l.buttonId)),e({type:0});break;case V.Escape:if(l.popoverState!==0)return y==null?void 0:y(l.buttonId);if(!g.current||E!=null&&E.activeElement&&!g.current.contains(E.activeElement))return;r.preventDefault(),r.stopPropagation(),e({type:1});break}}),O=R(r=>{s||r.key===V.Space&&r.preventDefault()}),_=R(r=>{var T,A;Ae(r.currentTarget)||m||(s?(e({type:1}),(T=l.button)==null||T.focus()):(r.preventDefault(),r.stopPropagation(),l.popoverState===1&&(y==null||y(l.buttonId)),e({type:0}),(A=l.button)==null||A.focus()))}),Y=R(r=>{r.preventDefault(),r.stopPropagation()}),{isFocusVisible:K,focusProps:j}=Fe({autoFocus:v}),{isHovered:h,hoverProps:B}=Ce({isDisabled:m}),{pressed:$,pressProps:G}=_e({disabled:m}),H=l.popoverState===0,P=D(()=>({open:H,active:$||H,disabled:m,hover:h,focus:K,autofocus:v}),[H,h,K,$,m,v]),o=Ge(t,g),u=s?Pe({ref:x,type:o,onKeyDown:I,onClick:_,disabled:m||void 0,autoFocus:v},j,B,G):Pe({ref:M,id:l.buttonId,type:o,"aria-expanded":l.popoverState===0,"aria-controls":l.panel?l.panelId:void 0,disabled:m||void 0,autoFocus:v,onKeyDown:I,onKeyUp:O,onClick:_,onMouseDown:Y},j,B,G),c=be(),C=R(()=>{let r=l.panel;if(!r)return;function T(){W(c.current,{[U.Forwards]:()=>w(r,k.First),[U.Backwards]:()=>w(r,k.Last)})===ie.Error&&w(fe().filter(N=>N.dataset.headlessuiFocusGuard!=="true"),W(c.current,{[U.Forwards]:k.Next,[U.Backwards]:k.Previous}),{relativeTo:l.button})}T()});return b.createElement(b.Fragment,null,Q({ourProps:u,theirProps:p,slot:P,defaultTag:at,name:"Popover.Button"}),H&&!s&&a&&b.createElement(se,{id:d,features:ue.Focusable,"data-headlessui-focus-guard":!0,as:"button",type:"button",onFocus:C}))}let st="div",ut=re.RenderStrategy|re.Static;function it(t,n){let f=oe(),{id:F=`headlessui-popover-overlay-${f}`,...m}=t,[{popoverState:v},p]=ne("Popover.Overlay"),l=J(n),e=Se(),a=(()=>e!==null?(e&X.Open)===X.Open:v===0)(),g=R(y=>{if(Ae(y.currentTarget))return y.preventDefault();p({type:1})}),d=D(()=>({open:v===0}),[v]);return Q({ourProps:{ref:l,id:F,"aria-hidden":!0,onClick:g},theirProps:m,slot:d,defaultTag:st,features:ut,visible:a,name:"Popover.Overlay"})}let ft="div",Pt=re.RenderStrategy|re.Static;function dt(t,n){let f=oe(),{id:F=`headlessui-popover-panel-${f}`,focus:m=!1,anchor:v,modal:p,...l}=t,[e,a]=ne("Popover.Panel"),{close:g,isPortalled:d}=ce("Popover.Panel"),L=`headlessui-focus-sentinel-before-${f}`,y=`headlessui-focus-sentinel-after-${f}`,S=q(null),[s,i]=We(v),M=Ve();v!=null&&p==null?p=!0:p==null&&(p=!1);let x=J(S,n,v?s:null,P=>{a({type:4,panel:P})}),E=pe(S),I=qe();Be(()=>(a({type:5,panelId:F}),()=>{a({type:5,panelId:null})}),[F,a]);let O=Se(),_=(()=>O!==null?(O&X.Open)===X.Open:e.popoverState===0)();he(e.button,()=>a({type:1}),_);let Y=R(P=>{var o;switch(P.key){case V.Escape:if(e.popoverState!==0||!S.current||E!=null&&E.activeElement&&!S.current.contains(E.activeElement))return;P.preventDefault(),P.stopPropagation(),a({type:1}),(o=e.button)==null||o.focus();break}});te(()=>{var P;t.static||e.popoverState===1&&((P=t.unmount)==null||P)&&a({type:4,panel:null})},[e.popoverState,t.unmount,t.static,a]),te(()=>{if(e.__demoMode||!m||e.popoverState!==0||!S.current)return;let P=E==null?void 0:E.activeElement;S.current.contains(P)||w(S.current,k.First)},[e.__demoMode,m,S,e.popoverState]);let K=D(()=>({open:e.popoverState===0,close:g}),[e,g]),j=Pe(v?M():{},{ref:x,id:F,onKeyDown:Y,onBlur:m&&e.popoverState===0?P=>{var u,c,C,r,T;let o=P.relatedTarget;o&&S.current&&((u=S.current)!=null&&u.contains(o)||(a({type:1}),((C=(c=e.beforePanelSentinel.current)==null?void 0:c.contains)!=null&&C.call(c,o)||(T=(r=e.afterPanelSentinel.current)==null?void 0:r.contains)!=null&&T.call(r,o))&&o.focus({preventScroll:!0})))}:void 0,tabIndex:-1,style:{...i,"--button-width":Le(e.button,!0).width}}),h=be(),B=R(()=>{let P=S.current;if(!P)return;function o(){W(h.current,{[U.Forwards]:()=>{var c;w(P,k.First)===ie.Error&&((c=e.afterPanelSentinel.current)==null||c.focus())},[U.Backwards]:()=>{var u;(u=e.button)==null||u.focus({preventScroll:!0})}})}o()}),$=R(()=>{let P=S.current;if(!P)return;function o(){W(h.current,{[U.Forwards]:()=>{var A;if(!e.button)return;let u=fe(),c=u.indexOf(e.button),C=u.slice(0,c+1),T=[...u.slice(c+1),...C];for(let N of T.slice())if(N.dataset.headlessuiFocusGuard==="true"||(A=e.panel)!=null&&A.contains(N)){let Te=T.indexOf(N);Te!==-1&&T.splice(Te,1)}w(T,k.First,{sorted:!1})},[U.Backwards]:()=>{var c;w(P,k.Previous)===ie.Error&&((c=e.button)==null||c.focus())}})}o()}),G=p?ge:v?Re:Me,H=p?{focusTrapFeatures:ze.None,features:je.ScrollLock,enabled:e.popoverState===0}:{};return(G===Re||G===ge)&&(d=!0),b.createElement(ae.Provider,{value:F},b.createElement(le.Provider,{value:{close:g,isPortalled:d}},b.createElement(G,{...H},_&&d&&b.createElement(se,{id:L,ref:e.beforePanelSentinel,features:ue.Focusable,"data-headlessui-focus-guard":!0,as:"button",type:"button",onFocus:B}),Q({mergeRefs:I,ourProps:j,theirProps:l,slot:K,defaultTag:ft,features:Pt,visible:_,name:"Popover.Panel"}),_&&d&&b.createElement(se,{id:y,ref:e.afterPanelSentinel,features:ue.Focusable,"data-headlessui-focus-guard":!0,as:"button",type:"button",onFocus:$}))))}let ct="div";function vt(t,n){let f=q(null),F=J(f,n),[m,v]=ye([]),p=He(),l=R(s=>{v(i=>{let M=i.indexOf(s);if(M!==-1){let x=i.slice();return x.splice(M,1),x}return i})}),e=R(s=>(v(i=>[...i,s]),()=>l(s))),a=R(()=>{var M;let s=Ye(f);if(!s)return!1;let i=s.activeElement;return(M=f.current)!=null&&M.contains(i)?!0:m.some(x=>{var E,I;return((E=s.getElementById(x.buttonId.current))==null?void 0:E.contains(i))||((I=s.getElementById(x.panelId.current))==null?void 0:I.contains(i))})}),g=R(s=>{for(let i of m)i.buttonId.current!==s&&i.close()}),d=D(()=>({registerPopover:e,unregisterPopover:l,isFocusWithinPopoverGroup:a,closeOthers:g,mainTreeNodeRef:p.mainTreeNodeRef}),[e,l,a,g,p.mainTreeNodeRef]),L=D(()=>({}),[]),y=t,S={ref:F};return b.createElement(ve.Provider,{value:d},Q({ourProps:S,theirProps:y,slot:L,defaultTag:ct,name:"Popover.Group"}),b.createElement(p.MainTreeNode,null))}let Tt=z(lt),mt=z(pt),yt=z(it),Et=z(dt),bt=z(vt),Zt=Object.assign(Tt,{Button:mt,Overlay:yt,Panel:Et,Group:bt});export{Zt as Popover,mt as PopoverButton,bt as PopoverGroup,yt as PopoverOverlay,Et 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}; |
@@ -9,4 +9,6 @@ import React, { type ElementType, type MutableRefObject, type Ref } from 'react'; | ||
type PortalPropsWeControl = never; | ||
export type PortalProps<TTag extends ElementType = typeof DEFAULT_PORTAL_TAG> = Props<TTag, PortalRenderPropArg, PortalPropsWeControl>; | ||
declare function PortalFn<TTag extends ElementType = typeof DEFAULT_PORTAL_TAG>(props: PortalProps<TTag>, ref: Ref<HTMLElement>): React.ReactPortal | null; | ||
export type PortalProps<TTag extends ElementType = typeof DEFAULT_PORTAL_TAG> = Props<TTag, PortalRenderPropArg, PortalPropsWeControl, { | ||
enabled?: boolean; | ||
}>; | ||
declare function PortalFn<TTag extends ElementType = typeof DEFAULT_PORTAL_TAG>(props: PortalProps<TTag>, ref: Ref<HTMLElement>): React.JSX.Element | null; | ||
declare let DEFAULT_GROUP_TAG: React.ExoticComponent<{ | ||
@@ -32,4 +34,5 @@ children?: React.ReactNode; | ||
export declare let Portal: _internal_ComponentPortal & { | ||
/** @deprecated use `<PortalGroup>` instead of `<Portal.Group>` */ | ||
Group: _internal_ComponentPortalGroup; | ||
}; | ||
export {}; |
@@ -1,1 +0,1 @@ | ||
"use client";import P,{Fragment as T,createContext as m,useContext as s,useEffect as d,useMemo as y,useRef as g,useState as R}from"react";import{createPortal as M}from"react-dom";import{useEvent as E}from'../../hooks/use-event.js';import{useIsoMorphicEffect as c}from'../../hooks/use-iso-morphic-effect.js';import{useOnUnmount as H}from'../../hooks/use-on-unmount.js';import{useOwnerDocument as G}from'../../hooks/use-owner.js';import{useServerHandoffComplete as O}from'../../hooks/use-server-handoff-complete.js';import{optionalRef as b,useSyncRefs as x}from'../../hooks/use-sync-refs.js';import{usePortalRoot as h}from'../../internal/portal-force-root.js';import{env as A}from'../../utils/env.js';import{forwardRefWithAs as L,render as _}from'../../utils/render.js';function F(a){let l=h(),n=s(C),e=G(a),[p,o]=R(()=>{if(!l&&n!==null||A.isServer)return null;let t=e==null?void 0:e.getElementById("headlessui-portal-root");if(t)return t;if(e===null)return null;let r=e.createElement("div");return r.setAttribute("id","headlessui-portal-root"),e.body.appendChild(r)});return d(()=>{p!==null&&(e!=null&&e.body.contains(p)||e==null||e.body.appendChild(p))},[p,e]),d(()=>{l||n!==null&&o(n.current)},[n,o,l]),p}let U=T;function D(a,l){let n=a,e=g(null),p=x(b(u=>{e.current=u}),l),o=G(e),t=F(e),[r]=R(()=>{var u;return A.isServer?null:(u=o==null?void 0:o.createElement("div"))!=null?u:null}),i=s(f),v=O();return c(()=>{!t||!r||t.contains(r)||(r.setAttribute("data-headlessui-portal",""),t.appendChild(r))},[t,r]),c(()=>{if(r&&i)return i.register(r)},[i,r]),H(()=>{var u;!t||!r||(r instanceof Node&&t.contains(r)&&t.removeChild(r),t.childNodes.length<=0&&((u=t.parentElement)==null||u.removeChild(t)))}),v?!t||!r?null:M(_({ourProps:{ref:p},theirProps:n,slot:{},defaultTag:U,name:"Portal"}),r):null}let N=T,C=m(null);function S(a,l){let{target:n,...e}=a,o={ref:x(l)};return P.createElement(C.Provider,{value:n},_({ourProps:o,theirProps:e,defaultTag:N,name:"Popover.Group"}))}let f=m(null);function $(){let a=s(f),l=g([]),n=E(o=>(l.current.push(o),a&&a.register(o),()=>e(o))),e=E(o=>{let t=l.current.indexOf(o);t!==-1&&l.current.splice(t,1),a&&a.unregister(o)}),p=y(()=>({register:n,unregister:e,portals:l}),[n,e,l]);return[l,y(()=>function({children:t}){return P.createElement(f.Provider,{value:p},t)},[p])]}let j=L(D),W=L(S),w=Object.assign(j,{Group:W});export{w as Portal,W as PortalGroup,$ as useNestedPortals}; | ||
"use client";import f,{Fragment as g,createContext as E,useContext as T,useEffect as R,useMemo as c,useRef as A,useState as G}from"react";import{createPortal as H}from"react-dom";import{useEvent as L}from'../../hooks/use-event.js';import{useIsoMorphicEffect as x}from'../../hooks/use-iso-morphic-effect.js';import{useOnUnmount as O}from'../../hooks/use-on-unmount.js';import{useOwnerDocument as _}from'../../hooks/use-owner.js';import{useServerHandoffComplete as h}from'../../hooks/use-server-handoff-complete.js';import{optionalRef as F,useSyncRefs as P}from'../../hooks/use-sync-refs.js';import{usePortalRoot as U}from'../../internal/portal-force-root.js';import{env as C}from'../../utils/env.js';import{forwardRefWithAs as m,render as d}from'../../utils/render.js';function D(p){let r=U(),l=T(v),e=_(p),[o,n]=G(()=>{var t;if(!r&&l!==null)return(t=l.current)!=null?t:null;if(C.isServer)return null;let u=e==null?void 0:e.getElementById("headlessui-portal-root");if(u)return u;if(e===null)return null;let a=e.createElement("div");return a.setAttribute("id","headlessui-portal-root"),e.body.appendChild(a)});return R(()=>{o!==null&&(e!=null&&e.body.contains(o)||e==null||e.body.appendChild(o))},[o,e]),R(()=>{r||l!==null&&n(l.current)},[l,n,r]),o}let M=g,N=m(function(r,l){let e=r,o=A(null),n=P(F(i=>{o.current=i}),l),u=_(o),a=D(o),[t]=G(()=>{var i;return C.isServer?null:(i=u==null?void 0:u.createElement("div"))!=null?i:null}),s=T(y),b=h();return x(()=>{!a||!t||a.contains(t)||(t.setAttribute("data-headlessui-portal",""),a.appendChild(t))},[a,t]),x(()=>{if(t&&s)return s.register(t)},[s,t]),O(()=>{var i;!a||!t||(t instanceof Node&&a.contains(t)&&a.removeChild(t),a.childNodes.length<=0&&((i=a.parentElement)==null||i.removeChild(a)))}),b?!a||!t?null:H(d({ourProps:{ref:n},theirProps:e,slot:{},defaultTag:M,name:"Portal"}),t):null});function S(p,r){let l=P(r),{enabled:e=!0,...o}=p;return e?f.createElement(N,{...o,ref:l}):d({ourProps:{ref:l},theirProps:o,slot:{},defaultTag:M,name:"Portal"})}let j=g,v=E(null);function W(p,r){let{target:l,...e}=p,n={ref:P(r)};return f.createElement(v.Provider,{value:l},d({ourProps:n,theirProps:e,defaultTag:j,name:"Popover.Group"}))}let y=E(null);function ee(){let p=T(y),r=A([]),l=L(n=>(r.current.push(n),p&&p.register(n),()=>e(n))),e=L(n=>{let u=r.current.indexOf(n);u!==-1&&r.current.splice(u,1),p&&p.unregister(n)}),o=c(()=>({register:l,unregister:e,portals:r}),[l,e,r]);return[r,c(()=>function({children:u}){return f.createElement(y.Provider,{value:o},u)},[o])]}let I=m(S),J=m(W),te=Object.assign(I,{Group:J});export{te as Portal,J as PortalGroup,ee as useNestedPortals}; |
@@ -68,2 +68,3 @@ import React, { type ElementType, type Ref } from 'react'; | ||
declare let RadioGroupRoot: _internal_ComponentRadioGroup; | ||
/** @deprecated use `<Radio>` instead of `<RadioGroupOption>` */ | ||
export declare let RadioGroupOption: _internal_ComponentRadioOption; | ||
@@ -76,3 +77,6 @@ export declare let Radio: _internal_ComponentRadio; | ||
export declare let RadioGroup: _internal_ComponentRadioGroup & { | ||
/** @deprecated use `<Radio>` instead of `<RadioGroup.Option>` */ | ||
Option: _internal_ComponentRadioOption; | ||
/** @deprecated use `<Radio>` instead of `<RadioGroup.Radio>` */ | ||
Radio: _internal_ComponentRadio; | ||
/** @deprecated use `<Label>` instead of `<RadioGroup.Label>` */ | ||
@@ -79,0 +83,0 @@ Label: _internal_ComponentRadioLabel; |
@@ -1,1 +0,1 @@ | ||
"use client";import{useFocusRing as Q}from"@react-aria/focus";import{useHover as Y}from"@react-aria/interactions";import G,{createContext as Z,useCallback as ye,useContext as ee,useMemo as x,useReducer as me,useRef as W}from"react";import{useByComparator as Re}from'../../hooks/use-by-comparator.js';import{useControllable as be}from'../../hooks/use-controllable.js';import{useEvent as S}from'../../hooks/use-event.js';import{useId as B}from'../../hooks/use-id.js';import{useIsoMorphicEffect as te}from'../../hooks/use-iso-morphic-effect.js';import{useLatestValue as oe}from'../../hooks/use-latest-value.js';import{useSyncRefs as K}from'../../hooks/use-sync-refs.js';import{useDisabled as re}from'../../internal/disabled.js';import{FormFields as ge}from'../../internal/form-fields.js';import{useProvidedId as Oe}from'../../internal/id.js';import{isDisabledReactIssue7711 as ne}from'../../utils/bugs.js';import{Focus as w,FocusResult as ie,focusIn as ae,sortByDomNode as Pe}from'../../utils/focus-management.js';import{attemptSubmit as ve}from'../../utils/form.js';import{match as De}from'../../utils/match.js';import{getOwnerDocument as Ae}from'../../utils/owner.js';import{forwardRefWithAs as $,mergeProps as pe,render as j}from'../../utils/render.js';import{Description as _e,useDescribedBy as Ee,useDescriptions as le}from'../description/description.js';import{Keys as I}from'../keyboard.js';import{Label as Ge,useLabelledBy as xe,useLabels as se}from'../label/label.js';var Ce=(e=>(e[e.RegisterOption=0]="RegisterOption",e[e.UnregisterOption=1]="UnregisterOption",e))(Ce||{});let he={[0](o,t){let e=[...o.options,{id:t.id,element:t.element,propsRef:t.propsRef}];return{...o,options:Pe(e,a=>a.element.current)}},[1](o,t){let e=o.options.slice(),a=o.options.findIndex(O=>O.id===t.id);return a===-1?o:(e.splice(a,1),{...o,options:e})}},V=Z(null);V.displayName="RadioGroupDataContext";function J(o){let t=ee(V);if(t===null){let e=new Error(`<${o} /> is missing a parent <RadioGroup /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(e,J),e}return t}let X=Z(null);X.displayName="RadioGroupActionsContext";function z(o){let t=ee(X);if(t===null){let e=new Error(`<${o} /> is missing a parent <RadioGroup /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(e,z),e}return t}function Le(o,t){return De(t.type,he,o,t)}let ke="div";function Fe(o,t){let e=B(),a=re(),{id:O=`headlessui-radiogroup-${e}`,value:T,defaultValue:y,form:p,name:d,onChange:u,by:c,disabled:m=a||!1,...R}=o,f=Re(c),[P,C]=me(Le,{options:[]}),i=P.options,[U,h]=se(),[v,L]=le(),D=W(null),M=K(D,t),[r,A]=be(T,u,y),k=x(()=>i.find(n=>!n.propsRef.current.disabled),[i]),b=x(()=>i.some(n=>f(n.propsRef.current.value,r)),[i,r]),l=S(n=>{var s;if(m||f(n,r))return!1;let F=(s=i.find(H=>f(H.propsRef.current.value,n)))==null?void 0:s.propsRef.current;return F!=null&&F.disabled?!1:(A==null||A(n),!0)}),_=S(n=>{let F=D.current;if(!F)return;let s=Ae(F),H=i.filter(g=>g.propsRef.current.disabled===!1).map(g=>g.element.current);switch(n.key){case I.Enter:ve(n.currentTarget);break;case I.ArrowLeft:case I.ArrowUp:if(n.preventDefault(),n.stopPropagation(),ae(H,w.Previous|w.WrapAround)===ie.Success){let E=i.find(N=>N.element.current===(s==null?void 0:s.activeElement));E&&l(E.propsRef.current.value)}break;case I.ArrowRight:case I.ArrowDown:if(n.preventDefault(),n.stopPropagation(),ae(H,w.Next|w.WrapAround)===ie.Success){let E=i.find(N=>N.element.current===(s==null?void 0:s.activeElement));E&&l(E.propsRef.current.value)}break;case I.Space:{n.preventDefault(),n.stopPropagation();let g=i.find(E=>E.element.current===(s==null?void 0:s.activeElement));g&&l(g.propsRef.current.value)}break}}),q=S(n=>(C({type:0,...n}),()=>C({type:1,id:n.id}))),de=x(()=>({value:r,firstOption:k,containsCheckedOption:b,disabled:m,compare:f,...P}),[r,k,b,m,f,P]),ue=x(()=>({registerOption:q,change:l}),[q,l]),ce={ref:M,id:O,role:"radiogroup","aria-labelledby":U,"aria-describedby":v,onKeyDown:_},fe=x(()=>({value:r}),[r]),Te=ye(()=>l(y),[l]);return G.createElement(L,{name:"RadioGroup.Description"},G.createElement(h,{name:"RadioGroup.Label"},G.createElement(X.Provider,{value:ue},G.createElement(V.Provider,{value:de},d!=null&&G.createElement(ge,{disabled:m,data:{[d]:r||"on"},overrides:{type:"radio",checked:r!=null},form:p,onReset:Te}),j({ourProps:ce,theirProps:R,slot:fe,defaultTag:ke,name:"RadioGroup"})))))}let Ie="div";function Ue(o,t){var b;let e=J("RadioGroup.Option"),a=z("RadioGroup.Option"),O=B(),{id:T=`headlessui-radiogroup-option-${O}`,value:y,disabled:p=e.disabled||!1,autoFocus:d=!1,...u}=o,c=W(null),m=K(c,t),[R,f]=se(),[P,C]=le(),i=oe({value:y,disabled:p});te(()=>a.registerOption({id:T,element:c,propsRef:i}),[T,a,c,i]);let U=S(l=>{var _;if(ne(l.currentTarget))return l.preventDefault();a.change(y)&&((_=c.current)==null||_.focus())}),h=((b=e.firstOption)==null?void 0:b.id)===T,{isFocusVisible:v,focusProps:L}=Q({autoFocus:d}),{isHovered:D,hoverProps:M}=Y({isDisabled:p}),r=e.compare(e.value,y),A=pe({ref:m,id:T,role:"radio","aria-checked":r?"true":"false","aria-labelledby":R,"aria-describedby":P,"aria-disabled":p?!0:void 0,tabIndex:(()=>p?-1:r||!e.containsCheckedOption&&h?0:-1)(),onClick:p?void 0:U,autoFocus:d},L,M),k=x(()=>({checked:r,disabled:p,active:v,hover:D,focus:v,autofocus:d}),[r,p,D,v,d]);return G.createElement(C,{name:"RadioGroup.Description"},G.createElement(f,{name:"RadioGroup.Label"},j({ourProps:A,theirProps:u,slot:k,defaultTag:Ie,name:"RadioGroup.Option"})))}let Me="span";function Se(o,t){var b;let e=J("Radio"),a=z("Radio"),O=B(),T=Oe(),y=re(),{id:p=T||`headlessui-radio-${O}`,value:d,disabled:u=e.disabled||y||!1,autoFocus:c=!1,...m}=o,R=W(null),f=K(R,t),P=xe(),C=Ee(),i=oe({value:d,disabled:u});te(()=>a.registerOption({id:p,element:R,propsRef:i}),[p,a,R,i]);let U=S(l=>{var _;if(ne(l.currentTarget))return l.preventDefault();a.change(d)&&((_=R.current)==null||_.focus())}),{isFocusVisible:h,focusProps:v}=Q({autoFocus:c}),{isHovered:L,hoverProps:D}=Y({isDisabled:u}),M=((b=e.firstOption)==null?void 0:b.id)===p,r=e.compare(e.value,d),A=pe({ref:f,id:p,role:"radio","aria-checked":r?"true":"false","aria-labelledby":P,"aria-describedby":C,"aria-disabled":u?!0:void 0,tabIndex:(()=>u?-1:r||!e.containsCheckedOption&&M?0:-1)(),autoFocus:c,onClick:u?void 0:U},v,D),k=x(()=>({checked:r,disabled:u,hover:L,focus:h,autofocus:c}),[r,u,L,h,c]);return j({ourProps:A,theirProps:m,slot:k,defaultTag:Me,name:"Radio"})}let He=$(Fe),we=$(Ue),dt=$(Se),Ne=Ge,We=_e,ut=Object.assign(He,{Option:we,Label:Ne,Description:We});export{dt as Radio,ut as RadioGroup,We as RadioGroupDescription,Ne as RadioGroupLabel,we as RadioGroupOption}; | ||
"use client";import{useFocusRing as Q}from"@react-aria/focus";import{useHover as Y}from"@react-aria/interactions";import G,{createContext as Z,useCallback as ye,useContext as ee,useMemo as x,useReducer as Re,useRef as W}from"react";import{useByComparator as be}from'../../hooks/use-by-comparator.js';import{useControllable as ge}from'../../hooks/use-controllable.js';import{useDefaultValue as Oe}from'../../hooks/use-default-value.js';import{useEvent as S}from'../../hooks/use-event.js';import{useId as B}from'../../hooks/use-id.js';import{useIsoMorphicEffect as te}from'../../hooks/use-iso-morphic-effect.js';import{useLatestValue as oe}from'../../hooks/use-latest-value.js';import{useSyncRefs as V}from'../../hooks/use-sync-refs.js';import{useDisabled as re}from'../../internal/disabled.js';import{FormFields as Pe}from'../../internal/form-fields.js';import{useProvidedId as ve}from'../../internal/id.js';import{isDisabledReactIssue7711 as ie}from'../../utils/bugs.js';import{Focus as w,FocusResult as ne,focusIn as ae,sortByDomNode as De}from'../../utils/focus-management.js';import{attemptSubmit as Ae}from'../../utils/form.js';import{match as _e}from'../../utils/match.js';import{getOwnerDocument as Ee}from'../../utils/owner.js';import{forwardRefWithAs as K,mergeProps as pe,render as $}from'../../utils/render.js';import{Description as Ge,useDescribedBy as xe,useDescriptions as le}from'../description/description.js';import{Keys as F}from'../keyboard.js';import{Label as Ce,useLabelledBy as he,useLabels as se}from'../label/label.js';var Le=(e=>(e[e.RegisterOption=0]="RegisterOption",e[e.UnregisterOption=1]="UnregisterOption",e))(Le||{});let ke={[0](o,t){let e=[...o.options,{id:t.id,element:t.element,propsRef:t.propsRef}];return{...o,options:De(e,a=>a.element.current)}},[1](o,t){let e=o.options.slice(),a=o.options.findIndex(O=>O.id===t.id);return a===-1?o:(e.splice(a,1),{...o,options:e})}},j=Z(null);j.displayName="RadioGroupDataContext";function J(o){let t=ee(j);if(t===null){let e=new Error(`<${o} /> is missing a parent <RadioGroup /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(e,J),e}return t}let X=Z(null);X.displayName="RadioGroupActionsContext";function z(o){let t=ee(X);if(t===null){let e=new Error(`<${o} /> is missing a parent <RadioGroup /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(e,z),e}return t}function Fe(o,t){return _e(t.type,ke,o,t)}let Ie="div";function Ue(o,t){let e=B(),a=re(),{id:O=`headlessui-radiogroup-${e}`,value:m,form:P,name:i,onChange:f,by:c,disabled:p=a||!1,defaultValue:I,...y}=o,T=be(c),[v,C]=Re(Fe,{options:[]}),n=v.options,[U,h]=se(),[D,L]=le(),A=W(null),M=V(A,t),l=Oe(I),[s,_]=ge(m,f,l),R=x(()=>n.find(r=>!r.propsRef.current.disabled),[n]),b=x(()=>n.some(r=>T(r.propsRef.current.value,s)),[n,s]),d=S(r=>{var u;if(p||T(r,s))return!1;let k=(u=n.find(H=>T(H.propsRef.current.value,r)))==null?void 0:u.propsRef.current;return k!=null&&k.disabled?!1:(_==null||_(r),!0)}),de=S(r=>{let k=A.current;if(!k)return;let u=Ee(k),H=n.filter(g=>g.propsRef.current.disabled===!1).map(g=>g.element.current);switch(r.key){case F.Enter:Ae(r.currentTarget);break;case F.ArrowLeft:case F.ArrowUp:if(r.preventDefault(),r.stopPropagation(),ae(H,w.Previous|w.WrapAround)===ne.Success){let E=n.find(N=>N.element.current===(u==null?void 0:u.activeElement));E&&d(E.propsRef.current.value)}break;case F.ArrowRight:case F.ArrowDown:if(r.preventDefault(),r.stopPropagation(),ae(H,w.Next|w.WrapAround)===ne.Success){let E=n.find(N=>N.element.current===(u==null?void 0:u.activeElement));E&&d(E.propsRef.current.value)}break;case F.Space:{r.preventDefault(),r.stopPropagation();let g=n.find(E=>E.element.current===(u==null?void 0:u.activeElement));g&&d(g.propsRef.current.value)}break}}),q=S(r=>(C({type:0,...r}),()=>C({type:1,id:r.id}))),ue=x(()=>({value:s,firstOption:R,containsCheckedOption:b,disabled:p,compare:T,...v}),[s,R,b,p,T,v]),ce=x(()=>({registerOption:q,change:d}),[q,d]),fe={ref:M,id:O,role:"radiogroup","aria-labelledby":U,"aria-describedby":D,onKeyDown:de},Te=x(()=>({value:s}),[s]),me=ye(()=>{if(l!==void 0)return d(l)},[d,l]);return G.createElement(L,{name:"RadioGroup.Description"},G.createElement(h,{name:"RadioGroup.Label"},G.createElement(X.Provider,{value:ce},G.createElement(j.Provider,{value:ue},i!=null&&G.createElement(Pe,{disabled:p,data:{[i]:s||"on"},overrides:{type:"radio",checked:s!=null},form:P,onReset:me}),$({ourProps:fe,theirProps:y,slot:Te,defaultTag:Ie,name:"RadioGroup"})))))}let Me="div";function Se(o,t){var R;let e=J("RadioGroup.Option"),a=z("RadioGroup.Option"),O=B(),{id:m=`headlessui-radiogroup-option-${O}`,value:P,disabled:i=e.disabled||!1,autoFocus:f=!1,...c}=o,p=W(null),I=V(p,t),[y,T]=se(),[v,C]=le(),n=oe({value:P,disabled:i});te(()=>a.registerOption({id:m,element:p,propsRef:n}),[m,a,p,n]);let U=S(b=>{var d;if(ie(b.currentTarget))return b.preventDefault();a.change(P)&&((d=p.current)==null||d.focus())}),h=((R=e.firstOption)==null?void 0:R.id)===m,{isFocusVisible:D,focusProps:L}=Q({autoFocus:f}),{isHovered:A,hoverProps:M}=Y({isDisabled:i}),l=e.compare(e.value,P),s=pe({ref:I,id:m,role:"radio","aria-checked":l?"true":"false","aria-labelledby":y,"aria-describedby":v,"aria-disabled":i?!0:void 0,tabIndex:(()=>i?-1:l||!e.containsCheckedOption&&h?0:-1)(),onClick:i?void 0:U,autoFocus:f},L,M),_=x(()=>({checked:l,disabled:i,active:D,hover:A,focus:D,autofocus:f}),[l,i,A,D,f]);return G.createElement(C,{name:"RadioGroup.Description"},G.createElement(T,{name:"RadioGroup.Label"},$({ourProps:s,theirProps:c,slot:_,defaultTag:Me,name:"RadioGroup.Option"})))}let He="span";function we(o,t){var R;let e=J("Radio"),a=z("Radio"),O=B(),m=ve(),P=re(),{id:i=m||`headlessui-radio-${O}`,value:f,disabled:c=e.disabled||P||!1,autoFocus:p=!1,...I}=o,y=W(null),T=V(y,t),v=he(),C=xe(),n=oe({value:f,disabled:c});te(()=>a.registerOption({id:i,element:y,propsRef:n}),[i,a,y,n]);let U=S(b=>{var d;if(ie(b.currentTarget))return b.preventDefault();a.change(f)&&((d=y.current)==null||d.focus())}),{isFocusVisible:h,focusProps:D}=Q({autoFocus:p}),{isHovered:L,hoverProps:A}=Y({isDisabled:c}),M=((R=e.firstOption)==null?void 0:R.id)===i,l=e.compare(e.value,f),s=pe({ref:T,id:i,role:"radio","aria-checked":l?"true":"false","aria-labelledby":v,"aria-describedby":C,"aria-disabled":c?!0:void 0,tabIndex:(()=>c?-1:l||!e.containsCheckedOption&&M?0:-1)(),autoFocus:p,onClick:c?void 0:U},D,A),_=x(()=>({checked:l,disabled:c,hover:L,focus:h,autofocus:p}),[l,c,L,h,p]);return $({ourProps:s,theirProps:I,slot:_,defaultTag:He,name:"Radio"})}let Ne=K(Ue),We=K(Se),Be=K(we),Ve=Ce,Ke=Ge,Tt=Object.assign(Ne,{Option:We,Radio:Be,Label:Ve,Description:Ke});export{Be as Radio,Tt as RadioGroup,Ke as RadioGroupDescription,Ve as RadioGroupLabel,We as RadioGroupOption}; |
@@ -44,2 +44,3 @@ import React, { type ElementType, type Ref } from 'react'; | ||
} | ||
/** @deprecated use `<Field>` instead of `<SwitchGroup>` */ | ||
export declare let SwitchGroup: _internal_ComponentSwitchGroup; | ||
@@ -51,2 +52,3 @@ /** @deprecated use `<Label>` instead of `<SwitchLabel>` */ | ||
export declare let Switch: _internal_ComponentSwitch & { | ||
/** @deprecated use `<Field>` instead of `<Switch.Group>` */ | ||
Group: _internal_ComponentSwitchGroup; | ||
@@ -53,0 +55,0 @@ /** @deprecated use `<Label>` instead of `<Switch.Label>` */ |
@@ -1,1 +0,1 @@ | ||
"use client";import{useFocusRing as V}from"@react-aria/focus";import{useHover as $}from"@react-aria/interactions";import l,{Fragment as q,createContext as z,useCallback as Q,useContext as Y,useMemo as C,useRef as Z,useState as L}from"react";import{useActivePress as ee}from'../../hooks/use-active-press.js';import{useControllable as te}from'../../hooks/use-controllable.js';import{useDisposables as oe}from'../../hooks/use-disposables.js';import{useEvent as m}from'../../hooks/use-event.js';import{useId as re}from'../../hooks/use-id.js';import{useResolveButtonType as ne}from'../../hooks/use-resolve-button-type.js';import{useSyncRefs as le}from'../../hooks/use-sync-refs.js';import{useDisabled as ie}from'../../internal/disabled.js';import{FormFields as ae}from'../../internal/form-fields.js';import{useProvidedId as se}from'../../internal/id.js';import{isDisabledReactIssue7711 as pe}from'../../utils/bugs.js';import{attemptSubmit as ce}from'../../utils/form.js';import{forwardRefWithAs as ue,mergeProps as de,render as G}from'../../utils/render.js';import{Description as me,useDescribedBy as fe,useDescriptions as be}from'../description/description.js';import{Keys as R}from'../keyboard.js';import{Label as he,useLabelledBy as Te,useLabels as ye}from'../label/label.js';let y=z(null);y.displayName="GroupContext";let Se=q;function we(n){var i;let[o,s]=L(null),[f,b]=ye(),[h,t]=be(),p=C(()=>({switch:o,setSwitch:s}),[o,s]),c={},T=n;return l.createElement(t,{name:"Switch.Description",value:h},l.createElement(b,{name:"Switch.Label",value:f,props:{htmlFor:(i=p.switch)==null?void 0:i.id,onClick(u){o&&(u.currentTarget instanceof HTMLLabelElement&&u.preventDefault(),o.click(),o.focus({preventScroll:!0}))}}},l.createElement(y.Provider,{value:p},G({ourProps:c,theirProps:T,slot:{},defaultTag:Se,name:"Switch.Group"}))))}let _e="button";function Pe(n,o){var x;let s=re(),f=se(),b=ie(),{id:h=f||`headlessui-switch-${s}`,disabled:t=b||!1,checked:p,defaultChecked:c=!1,onChange:T,name:i,value:u,form:A,autoFocus:d=!1,...F}=n,S=Y(y),w=Z(null),k=le(w,o,S===null?null:S.setSwitch),[a,r]=te(p,T,c),H=oe(),[_,P]=L(!1),E=m(()=>{P(!0),r==null||r(!a),H.nextFrame(()=>{P(!1)})}),M=m(e=>{if(pe(e.currentTarget))return e.preventDefault();e.preventDefault(),E()}),U=m(e=>{e.key===R.Space?(e.preventDefault(),E()):e.key===R.Enter&&ce(e.currentTarget)}),I=m(e=>e.preventDefault()),B=Te(),K=fe(),{isFocusVisible:g,focusProps:W}=V({autoFocus:d}),{isHovered:D,hoverProps:O}=$({isDisabled:t}),{pressed:v,pressProps:N}=ee({disabled:t}),J=C(()=>({checked:a,disabled:t,hover:D,focus:g,active:v,autofocus:d,changing:_}),[a,D,g,v,t,_,d]),X=de({id:h,ref:k,role:"switch",type:ne(n,w),tabIndex:n.tabIndex===-1?0:(x=n.tabIndex)!=null?x:0,"aria-checked":a,"aria-labelledby":B,"aria-describedby":K,disabled:t||void 0,autoFocus:d,onClick:M,onKeyUp:U,onKeyPress:I},W,O,N),j=Q(()=>r==null?void 0:r(c),[r]);return l.createElement(l.Fragment,null,i!=null&&l.createElement(ae,{disabled:t,data:{[i]:u||"on"},overrides:{type:"checkbox",checked:a},form:A,onReset:j}),G({ourProps:X,theirProps:F,slot:J,defaultTag:_e,name:"Switch"}))}let Ee=ue(Pe),ge=we,De=he,ve=me,je=Object.assign(Ee,{Group:ge,Label:De,Description:ve});export{je as Switch,ve as SwitchDescription,ge as SwitchGroup,De as SwitchLabel}; | ||
"use client";import{useFocusRing as z}from"@react-aria/focus";import{useHover as Q}from"@react-aria/interactions";import i,{Fragment as Y,createContext as Z,useCallback as ee,useContext as te,useMemo as L,useRef as oe,useState as S}from"react";import{useActivePress as re}from'../../hooks/use-active-press.js';import{useControllable as ne}from'../../hooks/use-controllable.js';import{useDefaultValue as le}from'../../hooks/use-default-value.js';import{useDisposables as ie}from'../../hooks/use-disposables.js';import{useEvent as m}from'../../hooks/use-event.js';import{useId as ae}from'../../hooks/use-id.js';import{useResolveButtonType as se}from'../../hooks/use-resolve-button-type.js';import{useSyncRefs as pe}from'../../hooks/use-sync-refs.js';import{useDisabled as ce}from'../../internal/disabled.js';import{FormFields as ue}from'../../internal/form-fields.js';import{useProvidedId as de}from'../../internal/id.js';import{isDisabledReactIssue7711 as me}from'../../utils/bugs.js';import{attemptSubmit as fe}from'../../utils/form.js';import{forwardRefWithAs as he,mergeProps as be,render as G}from'../../utils/render.js';import{Description as Te,useDescribedBy as ye,useDescriptions as Se}from'../description/description.js';import{Keys as R}from'../keyboard.js';import{Label as we,useLabelledBy as Ee,useLabels as _e}from'../label/label.js';let w=Z(null);w.displayName="GroupContext";let Pe=Y;function De(n){var a;let[o,p]=S(null),[f,h]=_e(),[b,t]=Se(),c=L(()=>({switch:o,setSwitch:p}),[o,p]),T={},y=n;return i.createElement(t,{name:"Switch.Description",value:b},i.createElement(h,{name:"Switch.Label",value:f,props:{htmlFor:(a=c.switch)==null?void 0:a.id,onClick(u){o&&(u.currentTarget instanceof HTMLLabelElement&&u.preventDefault(),o.click(),o.focus({preventScroll:!0}))}}},i.createElement(w.Provider,{value:c},G({ourProps:T,theirProps:y,slot:{},defaultTag:Pe,name:"Switch.Group"}))))}let ge="button";function ve(n,o){var C;let p=ae(),f=de(),h=ce(),{id:b=f||`headlessui-switch-${p}`,disabled:t=h||!1,checked:c,defaultChecked:T,onChange:y,name:a,value:u,form:A,autoFocus:d=!1,...F}=n,E=te(w),[H,k]=S(null),M=oe(null),U=pe(M,o,E===null?null:E.setSwitch,k),l=le(T),[s,r]=ne(c,y,l!=null?l:!1),I=ie(),[_,P]=S(!1),D=m(()=>{P(!0),r==null||r(!s),I.nextFrame(()=>{P(!1)})}),B=m(e=>{if(me(e.currentTarget))return e.preventDefault();e.preventDefault(),D()}),K=m(e=>{e.key===R.Space?(e.preventDefault(),D()):e.key===R.Enter&&fe(e.currentTarget)}),W=m(e=>e.preventDefault()),O=Ee(),N=ye(),{isFocusVisible:g,focusProps:J}=z({autoFocus:d}),{isHovered:v,hoverProps:V}=Q({isDisabled:t}),{pressed:x,pressProps:X}=re({disabled:t}),j=L(()=>({checked:s,disabled:t,hover:v,focus:g,active:x,autofocus:d,changing:_}),[s,v,g,x,t,_,d]),$=be({id:b,ref:U,role:"switch",type:se(n,H),tabIndex:n.tabIndex===-1?0:(C=n.tabIndex)!=null?C:0,"aria-checked":s,"aria-labelledby":O,"aria-describedby":N,disabled:t||void 0,autoFocus:d,onClick:B,onKeyUp:K,onKeyPress:W},J,V,X),q=ee(()=>{if(l!==void 0)return r==null?void 0:r(l)},[r,l]);return i.createElement(i.Fragment,null,a!=null&&i.createElement(ue,{disabled:t,data:{[a]:u||"on"},overrides:{type:"checkbox",checked:s},form:A,onReset:q}),G({ourProps:$,theirProps:F,slot:j,defaultTag:ge,name:"Switch"}))}let xe=he(ve),Ce=De,Le=we,Ge=Te,Qe=Object.assign(xe,{Group:Ce,Label:Le,Description:Ge});export{Qe as Switch,Ge as SwitchDescription,Ce as SwitchGroup,Le as SwitchLabel}; |
@@ -77,7 +77,11 @@ import React, { type ElementType, type Ref } from 'react'; | ||
export declare let Tab: _internal_ComponentTab & { | ||
/** @deprecated use `<TabGroup>` instead of `<Tab.Group>` */ | ||
Group: _internal_ComponentTabGroup; | ||
/** @deprecated use `<TabList>` instead of `<Tab.List>` */ | ||
List: _internal_ComponentTabList; | ||
/** @deprecated use `<TabPanels>` instead of `<Tab.Panels>` */ | ||
Panels: _internal_ComponentTabPanels; | ||
/** @deprecated use `<TabPanel>` instead of `<Tab.Panel>` */ | ||
Panel: _internal_ComponentTabPanel; | ||
}; | ||
export {}; |
@@ -1,1 +0,1 @@ | ||
"use client";import{useFocusRing as te}from"@react-aria/focus";import{useHover as de}from"@react-aria/interactions";import G,{createContext as re,useContext as ne,useMemo as D,useReducer as ce,useRef as q}from"react";import{useActivePress as fe}from'../../hooks/use-active-press.js';import{useEvent as S}from'../../hooks/use-event.js';import{useId as ae}from'../../hooks/use-id.js';import{useIsoMorphicEffect as W}from'../../hooks/use-iso-morphic-effect.js';import{useLatestValue as j}from'../../hooks/use-latest-value.js';import{useResolveButtonType as be}from'../../hooks/use-resolve-button-type.js';import{useSyncRefs as U}from'../../hooks/use-sync-refs.js';import{FocusSentinel as me}from'../../internal/focus-sentinel.js';import{Hidden as Pe}from'../../internal/hidden.js';import{Focus as P,FocusResult as K,focusIn as v,sortByDomNode as H}from'../../utils/focus-management.js';import{match as w}from'../../utils/match.js';import{microTask as ye}from'../../utils/micro-task.js';import{getOwnerDocument as xe}from'../../utils/owner.js';import{RenderFeatures as oe,forwardRefWithAs as O,mergeProps as le,render as N}from'../../utils/render.js';import{StableCollection as ge,useStableCollectionIndex as se}from'../../utils/stable-collection.js';import{Keys as y}from'../keyboard.js';var Ae=(t=>(t[t.Forwards=0]="Forwards",t[t.Backwards=1]="Backwards",t))(Ae||{}),Ee=(o=>(o[o.Less=-1]="Less",o[o.Equal=0]="Equal",o[o.Greater=1]="Greater",o))(Ee||{}),Re=(n=>(n[n.SetSelectedIndex=0]="SetSelectedIndex",n[n.RegisterTab=1]="RegisterTab",n[n.UnregisterTab=2]="UnregisterTab",n[n.RegisterPanel=3]="RegisterPanel",n[n.UnregisterPanel=4]="UnregisterPanel",n))(Re||{});let Le={[0](e,r){var c;let t=H(e.tabs,T=>T.current),o=H(e.panels,T=>T.current),a=t.filter(T=>{var d;return!((d=T.current)!=null&&d.hasAttribute("disabled"))}),n={...e,tabs:t,panels:o};if(r.index<0||r.index>t.length-1){let T=w(Math.sign(r.index-e.selectedIndex),{[-1]:()=>1,[0]:()=>w(Math.sign(r.index),{[-1]:()=>0,[0]:()=>0,[1]:()=>1}),[1]:()=>0});if(a.length===0)return n;let d=w(T,{[0]:()=>t.indexOf(a[0]),[1]:()=>t.indexOf(a[a.length-1])});return{...n,selectedIndex:d===-1?e.selectedIndex:d}}let u=t.slice(0,r.index),x=[...t.slice(r.index),...u].find(T=>a.includes(T));if(!x)return n;let f=(c=t.indexOf(x))!=null?c:e.selectedIndex;return f===-1&&(f=e.selectedIndex),{...n,selectedIndex:f}},[1](e,r){if(e.tabs.includes(r.tab))return e;let t=e.tabs[e.selectedIndex],o=H([...e.tabs,r.tab],n=>n.current),a=e.selectedIndex;return e.info.current.isControlled||(a=o.indexOf(t),a===-1&&(a=e.selectedIndex)),{...e,tabs:o,selectedIndex:a}},[2](e,r){return{...e,tabs:e.tabs.filter(t=>t!==r.tab)}},[3](e,r){return e.panels.includes(r.panel)?e:{...e,panels:H([...e.panels,r.panel],t=>t.current)}},[4](e,r){return{...e,panels:e.panels.filter(t=>t!==r.panel)}}},z=re(null);z.displayName="TabsDataContext";function C(e){let r=ne(z);if(r===null){let t=new Error(`<${e} /> is missing a parent <Tab.Group /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(t,C),t}return r}let V=re(null);V.displayName="TabsActionsContext";function Q(e){let r=ne(V);if(r===null){let t=new Error(`<${e} /> is missing a parent <Tab.Group /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(t,Q),t}return r}function _e(e,r){return w(r.type,Le,e,r)}let De="div";function Se(e,r){let{defaultIndex:t=0,vertical:o=!1,manual:a=!1,onChange:n,selectedIndex:u=null,..._}=e;const x=o?"vertical":"horizontal",f=a?"manual":"auto";let c=u!==null,T=j({isControlled:c}),d=U(r),[i,s]=ce(_e,{info:T,selectedIndex:u!=null?u:t,tabs:[],panels:[]}),F=D(()=>({selectedIndex:i.selectedIndex}),[i.selectedIndex]),M=j(n||(()=>{})),b=j(i.tabs),m=D(()=>({orientation:x,activation:f,...i}),[x,f,i]),E=S(p=>(s({type:1,tab:p}),()=>s({type:2,tab:p}))),I=S(p=>(s({type:3,panel:p}),()=>s({type:4,panel:p}))),g=S(p=>{R.current!==p&&M.current(p),c||s({type:0,index:p})}),R=j(c?e.selectedIndex:i.selectedIndex),J=D(()=>({registerTab:E,registerPanel:I,change:g}),[]);W(()=>{s({type:0,index:u!=null?u:t})},[u]),W(()=>{if(R.current===void 0||i.tabs.length<=0)return;let p=H(i.tabs,L=>L.current);p.some((L,B)=>i.tabs[B]!==L)&&g(p.indexOf(i.tabs[R.current]))});let k={ref:d};return G.createElement(ge,null,G.createElement(V.Provider,{value:J},G.createElement(z.Provider,{value:m},m.tabs.length<=0&&G.createElement(me,{onFocus:()=>{var p,h;for(let L of b.current)if(((p=L.current)==null?void 0:p.tabIndex)===0)return(h=L.current)==null||h.focus(),!0;return!1}}),N({ourProps:k,theirProps:_,slot:F,defaultTag:De,name:"Tabs"}))))}let Fe="div";function Ie(e,r){let{orientation:t,selectedIndex:o}=C("Tab.List"),a=U(r),n=D(()=>({selectedIndex:o}),[o]);return N({ourProps:{ref:a,role:"tablist","aria-orientation":t},theirProps:e,slot:n,defaultTag:Fe,name:"Tabs.List"})}let he="button";function ve(e,r){var Y,Z;let t=ae(),{id:o=`headlessui-tabs-tab-${t}`,disabled:a=!1,autoFocus:n=!1,...u}=e,{orientation:_,activation:x,selectedIndex:f,tabs:c,panels:T}=C("Tab"),d=Q("Tab"),i=C("Tab"),s=q(null),F=U(s,r);W(()=>d.registerTab(s),[d,s]);let M=se("tabs"),b=c.indexOf(s);b===-1&&(b=M);let m=b===f,E=S(l=>{var X;let A=l();if(A===K.Success&&x==="auto"){let $=(X=xe(s))==null?void 0:X.activeElement,ee=i.tabs.findIndex(Te=>Te.current===$);ee!==-1&&d.change(ee)}return A}),I=S(l=>{let A=c.map($=>$.current).filter(Boolean);if(l.key===y.Space||l.key===y.Enter){l.preventDefault(),l.stopPropagation(),d.change(b);return}switch(l.key){case y.Home:case y.PageUp:return l.preventDefault(),l.stopPropagation(),E(()=>v(A,P.First));case y.End:case y.PageDown:return l.preventDefault(),l.stopPropagation(),E(()=>v(A,P.Last))}if(E(()=>w(_,{vertical(){return l.key===y.ArrowUp?v(A,P.Previous|P.WrapAround):l.key===y.ArrowDown?v(A,P.Next|P.WrapAround):K.Error},horizontal(){return l.key===y.ArrowLeft?v(A,P.Previous|P.WrapAround):l.key===y.ArrowRight?v(A,P.Next|P.WrapAround):K.Error}}))===K.Success)return l.preventDefault()}),g=q(!1),R=S(()=>{var l;g.current||(g.current=!0,(l=s.current)==null||l.focus({preventScroll:!0}),d.change(b),ye(()=>{g.current=!1}))}),J=S(l=>{l.preventDefault()}),{isFocusVisible:k,focusProps:p}=te({autoFocus:n}),{isHovered:h,hoverProps:L}=de({isDisabled:a}),{pressed:B,pressProps:ie}=fe({disabled:a}),pe=D(()=>({selected:m,hover:h,active:B,focus:k,autofocus:n,disabled:a}),[m,h,k,B,n,a]),ue=le({ref:F,onKeyDown:I,onMouseDown:J,onClick:R,id:o,role:"tab",type:be(e,s),"aria-controls":(Z=(Y=T[b])==null?void 0:Y.current)==null?void 0:Z.id,"aria-selected":m,tabIndex:m?0:-1,disabled:a||void 0,autoFocus:n},p,L,ie);return N({ourProps:ue,theirProps:u,slot:pe,defaultTag:he,name:"Tabs.Tab"})}let Ce="div";function Me(e,r){let{selectedIndex:t}=C("Tab.Panels"),o=U(r),a=D(()=>({selectedIndex:t}),[t]);return N({ourProps:{ref:o},theirProps:e,slot:a,defaultTag:Ce,name:"Tabs.Panels"})}let Ge="div",Ue=oe.RenderStrategy|oe.Static;function He(e,r){var E,I,g,R;let t=ae(),{id:o=`headlessui-tabs-panel-${t}`,tabIndex:a=0,...n}=e,{selectedIndex:u,tabs:_,panels:x}=C("Tab.Panel"),f=Q("Tab.Panel"),c=q(null),T=U(c,r);W(()=>f.registerPanel(c),[f,c]);let d=se("panels"),i=x.indexOf(c);i===-1&&(i=d);let s=i===u,{isFocusVisible:F,focusProps:M}=te(),b=D(()=>({selected:s,focus:F}),[s,F]),m=le({ref:T,id:o,role:"tabpanel","aria-labelledby":(I=(E=_[i])==null?void 0:E.current)==null?void 0:I.id,tabIndex:s?a:-1},M);return!s&&((g=n.unmount)==null||g)&&!((R=n.static)!=null&&R)?G.createElement(Pe,{as:"span","aria-hidden":"true",...m}):N({ourProps:m,theirProps:n,slot:b,defaultTag:Ge,features:Ue,visible:s,name:"Tabs.Panel"})}let we=O(ve),Oe=O(Se),Ne=O(Ie),ke=O(Me),Be=O(He),st=Object.assign(we,{Group:Oe,List:Ne,Panels:ke,Panel:Be});export{st as Tab,Oe as TabGroup,Ne as TabList,Be as TabPanel,ke as TabPanels}; | ||
"use client";import{useFocusRing as re}from"@react-aria/focus";import{useHover as fe}from"@react-aria/interactions";import U,{createContext as ne,useContext as ae,useMemo as S,useReducer as be,useRef as q,useState as me}from"react";import{useActivePress as Pe}from'../../hooks/use-active-press.js';import{useEvent as F}from'../../hooks/use-event.js';import{useId as le}from'../../hooks/use-id.js';import{useIsoMorphicEffect as W}from'../../hooks/use-iso-morphic-effect.js';import{useLatestValue as j}from'../../hooks/use-latest-value.js';import{useResolveButtonType as ye}from'../../hooks/use-resolve-button-type.js';import{useSyncRefs as H}from'../../hooks/use-sync-refs.js';import{FocusSentinel as xe}from'../../internal/focus-sentinel.js';import{Hidden as ge}from'../../internal/hidden.js';import{Focus as P,FocusResult as K,focusIn as v,sortByDomNode as w}from'../../utils/focus-management.js';import{match as O}from'../../utils/match.js';import{microTask as Ae}from'../../utils/micro-task.js';import{getOwnerDocument as Ee}from'../../utils/owner.js';import{RenderFeatures as oe,forwardRefWithAs as N,mergeProps as se,render as k}from'../../utils/render.js';import{StableCollection as Le,useStableCollectionIndex as ie}from'../../utils/stable-collection.js';import{Keys as y}from'../keyboard.js';var Re=(t=>(t[t.Forwards=0]="Forwards",t[t.Backwards=1]="Backwards",t))(Re||{}),_e=(l=>(l[l.Less=-1]="Less",l[l.Equal=0]="Equal",l[l.Greater=1]="Greater",l))(_e||{}),De=(n=>(n[n.SetSelectedIndex=0]="SetSelectedIndex",n[n.RegisterTab=1]="RegisterTab",n[n.UnregisterTab=2]="UnregisterTab",n[n.RegisterPanel=3]="RegisterPanel",n[n.UnregisterPanel=4]="UnregisterPanel",n))(De||{});let Se={[0](e,r){var d;let t=w(e.tabs,u=>u.current),l=w(e.panels,u=>u.current),a=t.filter(u=>{var T;return!((T=u.current)!=null&&T.hasAttribute("disabled"))}),n={...e,tabs:t,panels:l};if(r.index<0||r.index>t.length-1){let u=O(Math.sign(r.index-e.selectedIndex),{[-1]:()=>1,[0]:()=>O(Math.sign(r.index),{[-1]:()=>0,[0]:()=>0,[1]:()=>1}),[1]:()=>0});if(a.length===0)return n;let T=O(u,{[0]:()=>t.indexOf(a[0]),[1]:()=>t.indexOf(a[a.length-1])});return{...n,selectedIndex:T===-1?e.selectedIndex:T}}let p=t.slice(0,r.index),x=[...t.slice(r.index),...p].find(u=>a.includes(u));if(!x)return n;let f=(d=t.indexOf(x))!=null?d:e.selectedIndex;return f===-1&&(f=e.selectedIndex),{...n,selectedIndex:f}},[1](e,r){if(e.tabs.includes(r.tab))return e;let t=e.tabs[e.selectedIndex],l=w([...e.tabs,r.tab],n=>n.current),a=e.selectedIndex;return e.info.current.isControlled||(a=l.indexOf(t),a===-1&&(a=e.selectedIndex)),{...e,tabs:l,selectedIndex:a}},[2](e,r){return{...e,tabs:e.tabs.filter(t=>t!==r.tab)}},[3](e,r){return e.panels.includes(r.panel)?e:{...e,panels:w([...e.panels,r.panel],t=>t.current)}},[4](e,r){return{...e,panels:e.panels.filter(t=>t!==r.panel)}}},z=ne(null);z.displayName="TabsDataContext";function C(e){let r=ae(z);if(r===null){let t=new Error(`<${e} /> is missing a parent <Tab.Group /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(t,C),t}return r}let V=ne(null);V.displayName="TabsActionsContext";function Q(e){let r=ae(V);if(r===null){let t=new Error(`<${e} /> is missing a parent <Tab.Group /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(t,Q),t}return r}function Fe(e,r){return O(r.type,Se,e,r)}let Ie="div";function he(e,r){let{defaultIndex:t=0,vertical:l=!1,manual:a=!1,onChange:n,selectedIndex:p=null,..._}=e;const x=l?"vertical":"horizontal",f=a?"manual":"auto";let d=p!==null,u=j({isControlled:d}),T=H(r),[s,c]=be(Fe,{info:u,selectedIndex:p!=null?p:t,tabs:[],panels:[]}),I=S(()=>({selectedIndex:s.selectedIndex}),[s.selectedIndex]),m=j(n||(()=>{})),M=j(s.tabs),D=S(()=>({orientation:x,activation:f,...s}),[x,f,s]),b=F(i=>(c({type:1,tab:i}),()=>c({type:2,tab:i}))),g=F(i=>(c({type:3,panel:i}),()=>c({type:4,panel:i}))),A=F(i=>{L.current!==i&&m.current(i),d||c({type:0,index:i})}),L=j(d?e.selectedIndex:s.selectedIndex),G=S(()=>({registerTab:b,registerPanel:g,change:A}),[]);W(()=>{c({type:0,index:p!=null?p:t})},[p]),W(()=>{if(L.current===void 0||s.tabs.length<=0)return;let i=w(s.tabs,R=>R.current);i.some((R,B)=>s.tabs[B]!==R)&&A(i.indexOf(s.tabs[L.current]))});let J={ref:T};return U.createElement(Le,null,U.createElement(V.Provider,{value:G},U.createElement(z.Provider,{value:D},D.tabs.length<=0&&U.createElement(xe,{onFocus:()=>{var i,h;for(let R of M.current)if(((i=R.current)==null?void 0:i.tabIndex)===0)return(h=R.current)==null||h.focus(),!0;return!1}}),k({ourProps:J,theirProps:_,slot:I,defaultTag:Ie,name:"Tabs"}))))}let ve="div";function Ce(e,r){let{orientation:t,selectedIndex:l}=C("Tab.List"),a=H(r),n=S(()=>({selectedIndex:l}),[l]);return k({ourProps:{ref:a,role:"tablist","aria-orientation":t},theirProps:e,slot:n,defaultTag:ve,name:"Tabs.List"})}let Me="button";function Ge(e,r){var Z,ee;let t=le(),{id:l=`headlessui-tabs-tab-${t}`,disabled:a=!1,autoFocus:n=!1,...p}=e,{orientation:_,activation:x,selectedIndex:f,tabs:d,panels:u}=C("Tab"),T=Q("Tab"),s=C("Tab"),[c,I]=me(null),m=q(null),M=H(m,r,I);W(()=>T.registerTab(m),[T,m]);let D=ie("tabs"),b=d.indexOf(m);b===-1&&(b=D);let g=b===f,A=F(o=>{var X;let E=o();if(E===K.Success&&x==="auto"){let $=(X=Ee(m))==null?void 0:X.activeElement,te=s.tabs.findIndex(ce=>ce.current===$);te!==-1&&T.change(te)}return E}),L=F(o=>{let E=d.map($=>$.current).filter(Boolean);if(o.key===y.Space||o.key===y.Enter){o.preventDefault(),o.stopPropagation(),T.change(b);return}switch(o.key){case y.Home:case y.PageUp:return o.preventDefault(),o.stopPropagation(),A(()=>v(E,P.First));case y.End:case y.PageDown:return o.preventDefault(),o.stopPropagation(),A(()=>v(E,P.Last))}if(A(()=>O(_,{vertical(){return o.key===y.ArrowUp?v(E,P.Previous|P.WrapAround):o.key===y.ArrowDown?v(E,P.Next|P.WrapAround):K.Error},horizontal(){return o.key===y.ArrowLeft?v(E,P.Previous|P.WrapAround):o.key===y.ArrowRight?v(E,P.Next|P.WrapAround):K.Error}}))===K.Success)return o.preventDefault()}),G=q(!1),J=F(()=>{var o;G.current||(G.current=!0,(o=m.current)==null||o.focus({preventScroll:!0}),T.change(b),Ae(()=>{G.current=!1}))}),i=F(o=>{o.preventDefault()}),{isFocusVisible:h,focusProps:R}=re({autoFocus:n}),{isHovered:B,hoverProps:pe}=fe({isDisabled:a}),{pressed:Y,pressProps:ue}=Pe({disabled:a}),Te=S(()=>({selected:g,hover:B,active:Y,focus:h,autofocus:n,disabled:a}),[g,B,h,Y,n,a]),de=se({ref:M,onKeyDown:L,onMouseDown:i,onClick:J,id:l,role:"tab",type:ye(e,c),"aria-controls":(ee=(Z=u[b])==null?void 0:Z.current)==null?void 0:ee.id,"aria-selected":g,tabIndex:g?0:-1,disabled:a||void 0,autoFocus:n},R,pe,ue);return k({ourProps:de,theirProps:p,slot:Te,defaultTag:Me,name:"Tabs.Tab"})}let Ue="div";function He(e,r){let{selectedIndex:t}=C("Tab.Panels"),l=H(r),a=S(()=>({selectedIndex:t}),[t]);return k({ourProps:{ref:l},theirProps:e,slot:a,defaultTag:Ue,name:"Tabs.Panels"})}let we="div",Oe=oe.RenderStrategy|oe.Static;function Ne(e,r){var b,g,A,L;let t=le(),{id:l=`headlessui-tabs-panel-${t}`,tabIndex:a=0,...n}=e,{selectedIndex:p,tabs:_,panels:x}=C("Tab.Panel"),f=Q("Tab.Panel"),d=q(null),u=H(d,r);W(()=>f.registerPanel(d),[f,d]);let T=ie("panels"),s=x.indexOf(d);s===-1&&(s=T);let c=s===p,{isFocusVisible:I,focusProps:m}=re(),M=S(()=>({selected:c,focus:I}),[c,I]),D=se({ref:u,id:l,role:"tabpanel","aria-labelledby":(g=(b=_[s])==null?void 0:b.current)==null?void 0:g.id,tabIndex:c?a:-1},m);return!c&&((A=n.unmount)==null||A)&&!((L=n.static)!=null&&L)?U.createElement(ge,{"aria-hidden":"true",...D}):k({ourProps:D,theirProps:n,slot:M,defaultTag:we,features:Oe,visible:c,name:"Tabs.Panel"})}let ke=N(Ge),Be=N(he),We=N(Ce),je=N(He),Ke=N(Ne),ut=Object.assign(ke,{Group:Be,List:We,Panels:je,Panel:Ke});export{ut as Tab,Be as TabGroup,We as TabList,Ke as TabPanel,je as TabPanels}; |
@@ -1,1 +0,1 @@ | ||
"use client";var J=Object.defineProperty;var X=(o,e,t)=>e in o?J(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var f=(o,e,t)=>(X(o,typeof e!="symbol"?e+"":e,t),t);import{useFocusRing as $}from"@react-aria/focus";import{useHover as j}from"@react-aria/interactions";import c,{Fragment as A,createContext as w,useContext as C,useEffect as q,useId as z,useMemo as P,useReducer as Q,useRef as M,useSyncExternalStore as Y}from"react";import{useDisposables as Z}from'../../hooks/use-disposables.js';import{useEvent as p}from'../../hooks/use-event.js';import{useSyncRefs as b}from'../../hooks/use-sync-refs.js';import{FloatingProvider as ee,useFloatingPanel as te,useFloatingReference as oe}from'../../internal/floating.js';import{State as G,useOpenClosed as ie}from'../../internal/open-closed.js';import{match as a}from'../../utils/match.js';import{RenderFeatures as O,forwardRefWithAs as R,mergeProps as re,render as I}from'../../utils/render.js';import{Description as U,useDescribedBy as ne,useDescriptions as le}from'../description/description.js';import{Keys as F}from'../keyboard.js';import{Portal as pe}from'../portal/portal.js';var ae=(r=>(r[r.Hidden=0]="Hidden",r[r.Initiated=1]="Initiated",r[r.Visible=2]="Visible",r[r.Hiding=3]="Hiding",r))(ae||{}),se=(t=>(t[t.Delayed=0]="Delayed",t[t.Immediate=1]="Immediate",t))(se||{});class Te{constructor(){f(this,"_state",null);f(this,"_listeners",[]);f(this,"subscribe",e=>(this._listeners.push(e),()=>{this._listeners=this._listeners.filter(t=>t!==e)}));f(this,"getSnapshot",()=>this._state);f(this,"getServerSnapshot",()=>this._state);f(this,"setTooltipId",e=>{this._state!==e&&(this._state=e,this._listeners.forEach(t=>t(e)))})}}let S=new Te;var de=(t=>(t[t.ShowTooltip=0]="ShowTooltip",t[t.HideTooltip=1]="HideTooltip",t))(de||{});let ue={[0](o,e){return{...o,tooltipState:a(o.tooltipState,{[0]:a(e.when,{[1]:2,[0]:1}),[1]:a(e.when,{[1]:2,[0]:1}),[2]:2,[3]:2})}},[1](o,e){return{...o,tooltipState:a(o.tooltipState,{[0]:0,[1]:0,[2]:a(e.when,{[1]:0,[0]:3}),[3]:a(e.when,{[1]:0,[0]:3})})}}},H=w(null);H.displayName="TooltipActionsContext";function V(o){let e=C(H);if(e===null){let t=new Error(`<${o} /> is missing a parent <Tooltip /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(t,V),t}return e}let x=w(null);x.displayName="TooltipDataContext";function W(o){let e=C(x);if(e===null){let t=new Error(`<${o} /> is missing a parent <Tooltip /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(t,W),t}return e}function me(o,e){return a(e.type,ue,o,e)}let fe=A;function ge(o,e){let{id:t=`headlessui-tooltip-${z()}`,showDelayMs:s=750,hideDelayMs:r=300,...T}=o,i=Y(S.subscribe,S.getSnapshot,S.getServerSnapshot),[n,g]=Q(me,{id:t,tooltipState:0}),[y,m]=le(),d=Z();q(()=>{d.dispose(),a(n.tooltipState,{[0](){},[1](){d.setTimeout(()=>u(1),s)},[2](){},[3](){d.setTimeout(()=>h(1),r)}})},[d,n.tooltipState,s,r]);let u=p(l=>{l===0&&i!==null&&i!==t&&(l=1),l===1&&S.setTooltipId(t),g({type:0,when:l})}),h=p(l=>{i===t&&l===1&&S.setTooltipId(null),g({type:1,when:l})}),E={ref:b(e)},D=P(()=>({}),[]),_=P(()=>({visible:i===n.id&&a(n.tooltipState,{[0]:!1,[1]:!1,[2]:!0,[3]:!0}),...n}),[i,n]),v=P(()=>({showTooltip:u,hideTooltip:h}),[u,h]);return c.createElement(m,{value:y},c.createElement(ee,null,c.createElement(H.Provider,{value:v},c.createElement(x.Provider,{value:_},I({ourProps:E,theirProps:T,slot:D,defaultTag:fe,name:"Tooltip"})))))}let ye=A;function ce(o,e){let{disabled:t=!1,autoFocus:s=!1,...r}=o,T=W("TooltipTrigger"),i=V("TooltipTrigger"),n=ne(),g=M(null),y=b(g,e,oe()),{isFocusVisible:m,focusProps:d}=$({autoFocus:s}),{isHovered:u,hoverProps:h}=j({isDisabled:t}),L=p(K=>{switch(K.key){case F.Enter:case F.Escape:case F.Space:if(T.tooltipState===2)return i.hideTooltip(1);break}}),E=p(()=>{i.showTooltip(1)}),D=p(()=>{i.hideTooltip(1)}),_=p(()=>{i.hideTooltip(1)}),v=p(()=>{i.showTooltip(0)}),l=p(()=>{i.hideTooltip(0)}),N=p(()=>{T.tooltipState===3&&i.showTooltip(1)}),B=P(()=>({hover:u,focus:m,autofocus:s}),[u,m,s]),k=re({ref:y,"aria-describedby":T.visible?n:void 0,onKeyDown:L,onFocus:E,onBlur:D,onMouseDown:_,onMouseEnter:v,onMouseLeave:l,onMouseMove:N},d,h);return I({ourProps:k,theirProps:r,slot:B,defaultTag:ye,name:"TooltipTrigger"})}let we=U,he=O.RenderStrategy|O.Static;function Pe(o,e){let{anchor:t={to:"top",padding:8,gap:8,offset:-4},...s}=o,r=W("TooltipPanel"),T=ie(),i=(()=>T!==null?(T&G.Open)===G.Open:r.visible)(),n=M(null),[g,y]=te(i?t:void 0),m=b(n,e,g),d={ref:m,role:"tooltip",...y?{style:y}:{}},u=P(()=>({}),[]);return I({ourProps:{...d,as:A,children:c.createElement(pe,null,c.createElement(U,{ref:m,...s}))},theirProps:{},slot:u,defaultTag:A,features:he,visible:i,name:"TooltipPanel"})}let Ce=R(ge),Me=R(ce),Ge=R(Pe);export{Ce as Tooltip,Ge as TooltipPanel,Me as TooltipTrigger}; | ||
"use client";var J=Object.defineProperty;var X=(o,t,e)=>t in o?J(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var g=(o,t,e)=>(X(o,typeof t!="symbol"?t+"":t,e),e);import{useFocusRing as $}from"@react-aria/focus";import{useHover as j}from"@react-aria/interactions";import c,{Fragment as A,createContext as w,useContext as C,useEffect as q,useId as z,useMemo as P,useReducer as Q,useRef as M,useSyncExternalStore as Y}from"react";import{useDisposables as Z}from'../../hooks/use-disposables.js';import{useEvent as a}from'../../hooks/use-event.js';import{useSyncRefs as b}from'../../hooks/use-sync-refs.js';import{FloatingProvider as ee,useFloatingPanel as te,useFloatingReference as oe,useResolvedAnchor as ie}from'../../internal/floating.js';import{State as G,useOpenClosed as re}from'../../internal/open-closed.js';import{match as s}from'../../utils/match.js';import{RenderFeatures as O,forwardRefWithAs as R,mergeProps as ne,render as I}from'../../utils/render.js';import{Description as U,useDescribedBy as le,useDescriptions as pe}from'../description/description.js';import{Keys as F}from'../keyboard.js';import{Portal as ae}from'../portal/portal.js';var se=(r=>(r[r.Hidden=0]="Hidden",r[r.Initiated=1]="Initiated",r[r.Visible=2]="Visible",r[r.Hiding=3]="Hiding",r))(se||{}),Te=(e=>(e[e.Delayed=0]="Delayed",e[e.Immediate=1]="Immediate",e))(Te||{});class de{constructor(){g(this,"_state",null);g(this,"_listeners",[]);g(this,"subscribe",t=>(this._listeners.push(t),()=>{this._listeners=this._listeners.filter(e=>e!==t)}));g(this,"getSnapshot",()=>this._state);g(this,"getServerSnapshot",()=>this._state);g(this,"setTooltipId",t=>{this._state!==t&&(this._state=t,this._listeners.forEach(e=>e(t)))})}}let S=new de;var ue=(e=>(e[e.ShowTooltip=0]="ShowTooltip",e[e.HideTooltip=1]="HideTooltip",e))(ue||{});let me={[0](o,t){return{...o,tooltipState:s(o.tooltipState,{[0]:s(t.when,{[1]:2,[0]:1}),[1]:s(t.when,{[1]:2,[0]:1}),[2]:2,[3]:2})}},[1](o,t){return{...o,tooltipState:s(o.tooltipState,{[0]:0,[1]:0,[2]:s(t.when,{[1]:0,[0]:3}),[3]:s(t.when,{[1]:0,[0]:3})})}}},H=w(null);H.displayName="TooltipActionsContext";function V(o){let t=C(H);if(t===null){let e=new Error(`<${o} /> is missing a parent <Tooltip /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(e,V),e}return t}let x=w(null);x.displayName="TooltipDataContext";function W(o){let t=C(x);if(t===null){let e=new Error(`<${o} /> is missing a parent <Tooltip /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(e,W),e}return t}function fe(o,t){return s(t.type,me,o,t)}let ge=A;function ye(o,t){let{id:e=`headlessui-tooltip-${z()}`,showDelayMs:T=750,hideDelayMs:r=300,...d}=o,i=Y(S.subscribe,S.getSnapshot,S.getServerSnapshot),[n,y]=Q(fe,{id:e,tooltipState:0}),[h,m]=pe(),l=Z();q(()=>{l.dispose(),s(n.tooltipState,{[0](){},[1](){l.setTimeout(()=>u(1),T)},[2](){},[3](){l.setTimeout(()=>f(1),r)}})},[l,n.tooltipState,T,r]);let u=a(p=>{p===0&&i!==null&&i!==e&&(p=1),p===1&&S.setTooltipId(e),y({type:0,when:p})}),f=a(p=>{i===e&&p===1&&S.setTooltipId(null),y({type:1,when:p})}),E={ref:b(t)},D=P(()=>({}),[]),_=P(()=>({visible:i===n.id&&s(n.tooltipState,{[0]:!1,[1]:!1,[2]:!0,[3]:!0}),...n}),[i,n]),v=P(()=>({showTooltip:u,hideTooltip:f}),[u,f]);return c.createElement(m,{value:h},c.createElement(ee,null,c.createElement(H.Provider,{value:v},c.createElement(x.Provider,{value:_},I({ourProps:E,theirProps:d,slot:D,defaultTag:ge,name:"Tooltip"})))))}let ce=A;function he(o,t){let{disabled:e=!1,autoFocus:T=!1,...r}=o,d=W("TooltipTrigger"),i=V("TooltipTrigger"),n=le(),y=M(null),h=b(y,t,oe()),{isFocusVisible:m,focusProps:l}=$({autoFocus:T}),{isHovered:u,hoverProps:f}=j({isDisabled:e}),L=a(K=>{switch(K.key){case F.Enter:case F.Escape:case F.Space:if(d.tooltipState===2)return i.hideTooltip(1);break}}),E=a(()=>{i.showTooltip(1)}),D=a(()=>{i.hideTooltip(1)}),_=a(()=>{i.hideTooltip(1)}),v=a(()=>{i.showTooltip(0)}),p=a(()=>{i.hideTooltip(0)}),N=a(()=>{d.tooltipState===3&&i.showTooltip(1)}),B=P(()=>({hover:u,focus:m,autofocus:T}),[u,m,T]),k=ne({ref:h,"aria-describedby":d.visible?n:void 0,onKeyDown:L,onFocus:E,onBlur:D,onMouseDown:_,onMouseEnter:v,onMouseLeave:p,onMouseMove:N},l,f);return I({ourProps:k,theirProps:r,slot:B,defaultTag:ce,name:"TooltipTrigger"})}let Ce=U,Pe=O.RenderStrategy|O.Static;function Se(o,t){let{anchor:e,...T}=o,r=W("TooltipPanel"),d=re(),i=(()=>d!==null?(d&G.Open)===G.Open:r.visible)(),n=M(null),y=ie(e!=null?e:{to:"top",padding:8,gap:8,offset:-4}),[h,m]=te(i?y:void 0),l=b(n,t,h),u={ref:l,role:"tooltip",...m?{style:m}:{}},f=P(()=>({}),[]);return I({ourProps:{...u,as:A,children:c.createElement(ae,null,c.createElement(U,{ref:l,...T}))},theirProps:{},slot:f,defaultTag:A,features:Pe,visible:i,name:"TooltipPanel"})}let Me=R(ye),Ge=R(he),Oe=R(Se);export{Me as Tooltip,Oe as TooltipPanel,Ge as TooltipTrigger}; |
@@ -24,2 +24,3 @@ import React, { type ElementType, type MutableRefObject, type Ref } from 'react'; | ||
export type TransitionChildProps<TTag extends ReactTag> = Props<TTag, TransitionChildRenderPropArg, TransitionChildPropsWeControl, PropsForFeatures<typeof TransitionChildRenderFeatures> & TransitionClasses & TransitionEvents & { | ||
transition?: boolean; | ||
appear?: boolean; | ||
@@ -30,3 +31,3 @@ }>; | ||
}>; | ||
type TransitionChildRenderPropArg = MutableRefObject<HTMLDivElement>; | ||
type TransitionChildRenderPropArg = MutableRefObject<HTMLElement>; | ||
declare let TransitionChildRenderFeatures: RenderFeatures; | ||
@@ -47,5 +48,7 @@ declare function TransitionChildFn<TTag extends ElementType = typeof DEFAULT_TRANSITION_CHILD_TAG>(props: TransitionChildProps<TTag>, ref: Ref<HTMLElement>): React.JSX.Element; | ||
export declare let Transition: _internal_ComponentTransitionRoot & { | ||
/** @deprecated use `<TransitionChild>` instead of `<Transition.Child>` */ | ||
Child: _internal_ComponentTransitionChild; | ||
/** @deprecated use `<Transition>` instead of `<Transition.Root>` */ | ||
Root: _internal_ComponentTransitionRoot; | ||
}; | ||
export {}; |
@@ -1,1 +0,1 @@ | ||
"use client";import T,{Fragment as B,createContext as oe,useContext as z,useMemo as se,useRef as E,useState as K}from"react";import{useDisposables as be}from'../../hooks/use-disposables.js';import{useEvent as S}from'../../hooks/use-event.js';import{useFlags as Ee}from'../../hooks/use-flags.js';import{useIsMounted as Se}from'../../hooks/use-is-mounted.js';import{useIsoMorphicEffect as I}from'../../hooks/use-iso-morphic-effect.js';import{useLatestValue as O}from'../../hooks/use-latest-value.js';import{useOnDisappear as Ne}from'../../hooks/use-on-disappear.js';import{useServerHandoffComplete as ae}from'../../hooks/use-server-handoff-complete.js';import{useSyncRefs as le}from'../../hooks/use-sync-refs.js';import{useTransition as ye}from'../../hooks/use-transition.js';import{OpenClosedProvider as Re,State as N,useOpenClosed as ue}from'../../internal/open-closed.js';import{classNames as Q}from'../../utils/class-names.js';import{match as _}from'../../utils/match.js';import{RenderFeatures as Pe,RenderStrategy as x,forwardRefWithAs as Y,render as Te}from'../../utils/render.js';function y(t=""){return t.split(/\s+/).filter(n=>n.length>1)}function de(t){var n;return!!(t.enter||t.enterFrom||t.enterTo||t.leave||t.leaveFrom||t.leaveTo)||((n=t.as)!=null?n:me)!==B||T.Children.count(t.children)===1}let W=oe(null);W.displayName="TransitionContext";var xe=(r=>(r.Visible="visible",r.Hidden="hidden",r))(xe||{});function De(){let t=z(W);if(t===null)throw new Error("A <Transition.Child /> is used but it is missing a parent <Transition /> or <Transition.Root />.");return t}function Fe(){let t=z(k);if(t===null)throw new Error("A <Transition.Child /> is used but it is missing a parent <Transition /> or <Transition.Root />.");return t}let k=oe(null);k.displayName="NestingContext";function q(t){return"children"in t?q(t.children):t.current.filter(({el:n})=>n.current!==null).filter(({state:n})=>n==="visible").length>0}function fe(t,n){let r=O(t),a=E([]),H=Se(),L=be(),p=S((i,e=x.Hidden)=>{let o=a.current.findIndex(({el:s})=>s===i);o!==-1&&(_(e,{[x.Unmount](){a.current.splice(o,1)},[x.Hidden](){a.current[o].state="hidden"}}),L.microTask(()=>{var s;!q(a)&&H.current&&((s=r.current)==null||s.call(r))}))}),D=S(i=>{let e=a.current.find(({el:o})=>o===i);return e?e.state!=="visible"&&(e.state="visible"):a.current.push({el:i,state:"visible"}),()=>p(i,x.Unmount)}),R=E([]),d=E(Promise.resolve()),C=E({enter:[],leave:[],idle:[]}),f=S((i,e,o)=>{R.current.splice(0),n&&(n.chains.current[e]=n.chains.current[e].filter(([s])=>s!==i)),n==null||n.chains.current[e].push([i,new Promise(s=>{R.current.push(s)})]),n==null||n.chains.current[e].push([i,new Promise(s=>{Promise.all(C.current[e].map(([g,m])=>m)).then(()=>s())})]),e==="enter"?d.current=d.current.then(()=>n==null?void 0:n.wait.current).then(()=>o(e)):o(e)}),h=S((i,e,o)=>{Promise.all(C.current[e].splice(0).map(([s,g])=>g)).then(()=>{var s;(s=R.current.shift())==null||s()}).then(()=>o(e))});return se(()=>({children:a,register:D,unregister:p,onStart:f,onStop:h,wait:d,chains:C}),[D,p,a,f,h,C,d])}let me=B,ce=Pe.RenderStrategy;function _e(t,n){var ne,re,ie;let{beforeEnter:r,afterEnter:a,beforeLeave:H,afterLeave:L,enter:p,enterFrom:D,enterTo:R,entered:d,leave:C,leaveFrom:f,leaveTo:h,...i}=t,e=E(null),o=de(t),s=le(...o?[e,n]:n===null?[]:[n]),g=(ne=i.unmount)==null||ne?x.Unmount:x.Hidden,{show:m,appear:V,initial:v}=De(),[P,J]=K(m?"visible":"hidden"),$=Fe(),{register:w,unregister:M}=$;I(()=>w(e),[w,e]),I(()=>{if(g===x.Hidden&&e.current){if(m&&P!=="visible"){J("visible");return}return _(P,{["hidden"]:()=>M(e),["visible"]:()=>w(e)})}},[P,e,w,M,m,g]);let F=O({base:y(i.className),enter:y(p),enterFrom:y(D),enterTo:y(R),entered:y(d),leave:y(C),leaveFrom:y(f),leaveTo:y(h)}),U=O({beforeEnter:r,afterEnter:a,beforeLeave:H,afterLeave:L}),X=ae();I(()=>{if(o&&X&&P==="visible"&&e.current===null)throw new Error("Did you forget to passthrough the `ref` to the actual DOM node?")},[e,P,X,o]);let Ce=v&&!V,ee=V&&m&&v,te=(()=>ee?"enter":!X||Ce?"idle":m?"enter":"leave")(),A=Ee(0),he=S(b=>_(b,{enter:()=>{var l,u;A.addFlag(N.Opening),(u=(l=U.current).beforeEnter)==null||u.call(l)},leave:()=>{var l,u;A.addFlag(N.Closing),(u=(l=U.current).beforeLeave)==null||u.call(l)},idle:()=>{}})),ge=S(b=>_(b,{enter:()=>{var l,u;A.removeFlag(N.Opening),(u=(l=U.current).afterEnter)==null||u.call(l)},leave:()=>{var l,u;A.removeFlag(N.Closing),(u=(l=U.current).afterLeave)==null||u.call(l)},idle:()=>{}})),j=E(!1),G=fe(()=>{j.current||(J("hidden"),M(e))},$);ye({container:e,classes:F,direction:te,onStart:O(b=>{j.current=!0,G.onStart(e,b,he)}),onStop:O(b=>{j.current=!1,G.onStop(e,b,ge),b==="leave"&&!q(G)&&(J("hidden"),M(e))})});let c=i,ve={ref:s};return ee?c={...c,className:Q(i.className,...F.current.enter,...F.current.enterFrom)}:j.current?(c.className=Q(i.className,(re=e.current)==null?void 0:re.className),c.className===""&&delete c.className):(c.className=Q(i.className,(ie=e.current)==null?void 0:ie.className,..._(te,{enter:[...F.current.enterTo,...F.current.entered],leave:F.current.leaveTo,idle:[]})),c.className===""&&delete c.className),T.createElement(k.Provider,{value:G},T.createElement(Re,{value:_(P,{["visible"]:N.Open,["hidden"]:N.Closed})|A.flags},Te({ourProps:ve,theirProps:c,defaultTag:me,features:ce,visible:P==="visible",name:"Transition.Child"})))}function He(t,n){let{show:r,appear:a=!1,unmount:H=!0,...L}=t,p=E(null),D=de(t),R=le(...D?[p,n]:n===null?[]:[n]);ae();let d=ue();if(r===void 0&&d!==null&&(r=(d&N.Open)===N.Open),r===void 0)throw new Error("A <Transition /> is used but it is missing a `show={true | false}` prop.");let[C,f]=K(r?"visible":"hidden"),h=fe(()=>{f("hidden")}),[i,e]=K(!0),o=E([r]);I(()=>{i!==!1&&o.current[o.current.length-1]!==r&&(o.current.push(r),e(!1))},[o,r]);let s=se(()=>({show:r,appear:a,initial:i}),[r,a,i]);Ne(p,()=>f("hidden")),I(()=>{r?f("visible"):q(h)||f("hidden")},[r,h]);let g={unmount:H},m=S(()=>{var v;i&&e(!1),(v=t.beforeEnter)==null||v.call(t)}),V=S(()=>{var v;i&&e(!1),(v=t.beforeLeave)==null||v.call(t)});return T.createElement(k.Provider,{value:h},T.createElement(W.Provider,{value:s},Te({ourProps:{...g,as:B,children:T.createElement(pe,{ref:R,...g,...L,beforeEnter:m,beforeLeave:V})},theirProps:{},defaultTag:B,features:ce,visible:C==="visible",name:"Transition"})))}function Le(t,n){let r=z(W)!==null,a=ue()!==null;return T.createElement(T.Fragment,null,!r&&a?T.createElement(Z,{ref:n,...t}):T.createElement(pe,{ref:n,...t}))}let Z=Y(He),pe=Y(_e),Ae=Y(Le),Ke=Object.assign(Z,{Child:Ae,Root:Z});export{Ke as Transition,Ae as TransitionChild}; | ||
"use client";import f,{Fragment as O,createContext as ne,useContext as q,useEffect as he,useMemo as ie,useRef as E,useState as V}from"react";import{useDisposables as ge}from'../../hooks/use-disposables.js';import{useEvent as S}from'../../hooks/use-event.js';import{useIsMounted as ve}from'../../hooks/use-is-mounted.js';import{useIsoMorphicEffect as H}from'../../hooks/use-iso-morphic-effect.js';import{useLatestValue as be}from'../../hooks/use-latest-value.js';import{useServerHandoffComplete as re}from'../../hooks/use-server-handoff-complete.js';import{useSyncRefs as oe}from'../../hooks/use-sync-refs.js';import{transitionDataAttributes as Ee,useTransition as Se}from'../../hooks/use-transition.js';import{OpenClosedProvider as ye,State as N,useOpenClosed as se}from'../../internal/open-closed.js';import{classNames as Re}from'../../utils/class-names.js';import{match as le}from'../../utils/match.js';import{RenderFeatures as Pe,RenderStrategy as x,compact as xe,forwardRefWithAs as J,render as ae}from'../../utils/render.js';function ue(e){var t;return!!(e.enter||e.enterFrom||e.enterTo||e.leave||e.leaveFrom||e.leaveTo)||((t=e.as)!=null?t:de)!==O||f.Children.count(e.children)===1}let w=ne(null);w.displayName="TransitionContext";var Ne=(n=>(n.Visible="visible",n.Hidden="hidden",n))(Ne||{});function _e(){let e=q(w);if(e===null)throw new Error("A <Transition.Child /> is used but it is missing a parent <Transition /> or <Transition.Root />.");return e}function De(){let e=q(M);if(e===null)throw new Error("A <Transition.Child /> is used but it is missing a parent <Transition /> or <Transition.Root />.");return e}let M=ne(null);M.displayName="NestingContext";function U(e){return"children"in e?U(e.children):e.current.filter(({el:t})=>t.current!==null).filter(({state:t})=>t==="visible").length>0}function Te(e,t){let n=be(e),l=E([]),y=ve(),R=ge(),T=S((o,i=x.Hidden)=>{let a=l.current.findIndex(({el:s})=>s===o);a!==-1&&(le(i,{[x.Unmount](){l.current.splice(a,1)},[x.Hidden](){l.current[a].state="hidden"}}),R.microTask(()=>{var s;!U(l)&&y.current&&((s=n.current)==null||s.call(n))}))}),P=S(o=>{let i=l.current.find(({el:a})=>a===o);return i?i.state!=="visible"&&(i.state="visible"):l.current.push({el:o,state:"visible"}),()=>T(o,x.Unmount)}),p=E([]),m=E(Promise.resolve()),C=E({enter:[],leave:[]}),h=S((o,i,a)=>{p.current.splice(0),t&&(t.chains.current[i]=t.chains.current[i].filter(([s])=>s!==o)),t==null||t.chains.current[i].push([o,new Promise(s=>{p.current.push(s)})]),t==null||t.chains.current[i].push([o,new Promise(s=>{Promise.all(C.current[i].map(([r,d])=>d)).then(()=>s())})]),i==="enter"?m.current=m.current.then(()=>t==null?void 0:t.wait.current).then(()=>a(i)):a(i)}),g=S((o,i,a)=>{Promise.all(C.current[i].splice(0).map(([s,r])=>r)).then(()=>{var s;(s=p.current.shift())==null||s()}).then(()=>a(i))});return ie(()=>({children:l,register:P,unregister:T,onStart:h,onStop:g,wait:m,chains:C}),[P,T,l,h,g,C,m])}let de=O,fe=Pe.RenderStrategy;function He(e,t){var ee,te;let{transition:n=!0,beforeEnter:l,afterEnter:y,beforeLeave:R,afterLeave:T,enter:P,enterFrom:p,enterTo:m,entered:C,leave:h,leaveFrom:g,leaveTo:o,...i}=e,[a,s]=V(null),r=E(null),d=ue(e),j=oe(...d?[r,t,s]:t===null?[]:[t]),v=(ee=i.unmount)==null||ee?x.Unmount:x.Hidden,{show:c,appear:z,initial:K}=_e(),[b,G]=V(c?"visible":"hidden"),Q=De(),{register:A,unregister:I}=Q;H(()=>A(r),[A,r]),H(()=>{if(v===x.Hidden&&r.current){if(c&&b!=="visible"){G("visible");return}return le(b,{["hidden"]:()=>I(r),["visible"]:()=>A(r)})}},[b,r,A,I,c,v]);let B=re();H(()=>{if(d&&B&&b==="visible"&&r.current===null)throw new Error("Did you forget to passthrough the `ref` to the actual DOM node?")},[r,b,B,d]);let ce=K&&!z,Y=z&&c&&K,W=E(!1),L=Te(()=>{W.current||(G("hidden"),I(r))},Q),Z=S(k=>{W.current=!0;let F=k?"enter":"leave";L.onStart(r,F,D=>{D==="enter"?l==null||l():D==="leave"&&(R==null||R())})}),$=S(k=>{let F=k?"enter":"leave";W.current=!1,L.onStop(r,F,D=>{D==="enter"?y==null||y():D==="leave"&&(T==null||T())}),F==="leave"&&!U(L)&&(G("hidden"),I(r))});he(()=>{d&&n||(Z(c),$(c))},[c,d,n]);let pe=(()=>!(!n||!d||!B||ce))(),[,u]=Se(pe,a,c,{start:Z,end:$}),Ce=xe({ref:j,className:((te=Re(i.className,Y&&P,Y&&p,u.enter&&P,u.enter&&u.closed&&p,u.enter&&!u.closed&&m,u.leave&&h,u.leave&&!u.closed&&g,u.leave&&u.closed&&o,!u.transition&&c&&C))==null?void 0:te.trim())||void 0,...Ee(u)}),_=0;return b==="visible"&&(_|=N.Open),b==="hidden"&&(_|=N.Closed),u.enter&&(_|=N.Opening),u.leave&&(_|=N.Closing),f.createElement(M.Provider,{value:L},f.createElement(ye,{value:_},ae({ourProps:Ce,theirProps:i,defaultTag:de,features:fe,visible:b==="visible",name:"Transition.Child"})))}function Ae(e,t){let{show:n,appear:l=!1,unmount:y=!0,...R}=e,T=E(null),P=ue(e),p=oe(...P?[T,t]:t===null?[]:[t]);re();let m=se();if(n===void 0&&m!==null&&(n=(m&N.Open)===N.Open),n===void 0)throw new Error("A <Transition /> is used but it is missing a `show={true | false}` prop.");let[C,h]=V(n?"visible":"hidden"),g=Te(()=>{n||h("hidden")}),[o,i]=V(!0),a=E([n]);H(()=>{o!==!1&&a.current[a.current.length-1]!==n&&(a.current.push(n),i(!1))},[a,n]);let s=ie(()=>({show:n,appear:l,initial:o}),[n,l,o]);H(()=>{n?h("visible"):!U(g)&&T.current!==null&&h("hidden")},[n,g]);let r={unmount:y},d=S(()=>{var v;o&&i(!1),(v=e.beforeEnter)==null||v.call(e)}),j=S(()=>{var v;o&&i(!1),(v=e.beforeLeave)==null||v.call(e)});return f.createElement(M.Provider,{value:g},f.createElement(w.Provider,{value:s},ae({ourProps:{...r,as:O,children:f.createElement(me,{ref:p,...r,...R,beforeEnter:d,beforeLeave:j})},theirProps:{},defaultTag:O,features:fe,visible:C==="visible",name:"Transition"})))}function Ie(e,t){let n=q(w)!==null,l=se()!==null;return f.createElement(f.Fragment,null,!n&&l?f.createElement(X,{ref:t,...e}):f.createElement(me,{ref:t,...e}))}let X=J(Ae),me=J(He),Le=J(Ie),Xe=Object.assign(X,{Child:Le,Root:X});export{Xe as Transition,Le as TransitionChild}; |
@@ -1,1 +0,1 @@ | ||
import{disposables as m}from'../../utils/disposables.js';import{isIOS as u}from'../../utils/platform.js';function d(){return u()?{before({doc:r,d:l,meta:c}){function o(a){return c.containers.flatMap(n=>n()).some(n=>n.contains(a))}l.microTask(()=>{var s;if(window.getComputedStyle(r.documentElement).scrollBehavior!=="auto"){let t=m();t.style(r.documentElement,"scrollBehavior","auto"),l.add(()=>l.microTask(()=>t.dispose()))}let a=(s=window.scrollY)!=null?s:window.pageYOffset,n=null;l.addEventListener(r,"click",t=>{if(t.target instanceof HTMLElement)try{let e=t.target.closest("a");if(!e)return;let{hash:f}=new URL(e.href),i=r.querySelector(f);i&&!o(i)&&(n=i)}catch{}},!0),l.addEventListener(r,"touchstart",t=>{if(t.target instanceof HTMLElement)if(o(t.target)){let e=t.target;for(;e.parentElement&&o(e.parentElement);)e=e.parentElement;l.style(e,"overscrollBehavior","contain")}else l.style(t.target,"touchAction","none")}),l.addEventListener(r,"touchmove",t=>{if(t.target instanceof HTMLElement)if(o(t.target)){let e=t.target;for(;e.parentElement&&e.dataset.headlessuiPortal!==""&&!(e.scrollHeight>e.clientHeight||e.scrollWidth>e.clientWidth);)e=e.parentElement;e.dataset.headlessuiPortal===""&&t.preventDefault()}else t.preventDefault()},{passive:!1}),l.add(()=>{var e;let t=(e=window.scrollY)!=null?e:window.pageYOffset;a!==t&&window.scrollTo(0,a),n&&n.isConnected&&(n.scrollIntoView({block:"nearest"}),n=null)})})}}:{}}export{d as handleIOSLocking}; | ||
import{disposables as m}from'../../utils/disposables.js';import{isIOS as u}from'../../utils/platform.js';function d(){return u()?{before({doc:r,d:n,meta:c}){function o(a){return c.containers.flatMap(l=>l()).some(l=>l.contains(a))}n.microTask(()=>{var s;if(window.getComputedStyle(r.documentElement).scrollBehavior!=="auto"){let t=m();t.style(r.documentElement,"scrollBehavior","auto"),n.add(()=>n.microTask(()=>t.dispose()))}let a=(s=window.scrollY)!=null?s:window.pageYOffset,l=null;n.addEventListener(r,"click",t=>{if(t.target instanceof HTMLElement)try{let e=t.target.closest("a");if(!e)return;let{hash:f}=new URL(e.href),i=r.querySelector(f);i&&!o(i)&&(l=i)}catch{}},!0),n.addEventListener(r,"touchstart",t=>{if(t.target instanceof HTMLElement)if(o(t.target)){let e=t.target;for(;e.parentElement&&o(e.parentElement);)e=e.parentElement;n.style(e,"overscrollBehavior","contain")}else n.style(t.target,"touchAction","none")}),n.addEventListener(r,"touchmove",t=>{if(t.target instanceof HTMLElement){if(t.target.tagName==="INPUT")return;if(o(t.target)){let e=t.target;for(;e.parentElement&&e.dataset.headlessuiPortal!==""&&!(e.scrollHeight>e.clientHeight||e.scrollWidth>e.clientWidth);)e=e.parentElement;e.dataset.headlessuiPortal===""&&t.preventDefault()}else t.preventDefault()}},{passive:!1}),n.add(()=>{var e;let t=(e=window.scrollY)!=null?e:window.pageYOffset;a!==t&&window.scrollTo(0,a),l&&l.isConnected&&(l.scrollIntoView({block:"nearest"}),l=null)})})}}:{}}export{d as handleIOSLocking}; |
@@ -1,1 +0,1 @@ | ||
export declare function useDocumentOverflowLockedEffect(doc: Document | null, shouldBeLocked: boolean, meta?: (meta: Record<string, any>) => Record<string, any>): boolean; | ||
export declare function useDocumentOverflowLockedEffect(shouldBeLocked: boolean, doc: Document | null, meta?: (meta: Record<string, any>) => Record<string, any>): boolean; |
@@ -1,1 +0,1 @@ | ||
import{useStore as s}from'../../hooks/use-store.js';import{useIsoMorphicEffect as u}from'../use-iso-morphic-effect.js';import{overflows as t}from'./overflow-store.js';function a(e,r,n=()=>({containers:[]})){let f=s(t),o=e?f.get(e):void 0,i=o?o.count>0:!1;return u(()=>{if(!(!e||!r))return t.dispatch("PUSH",e,n),()=>t.dispatch("POP",e,n)},[r,e]),i}export{a as useDocumentOverflowLockedEffect}; | ||
import{useStore as s}from'../../hooks/use-store.js';import{useIsoMorphicEffect as u}from'../use-iso-morphic-effect.js';import{overflows as t}from'./overflow-store.js';function a(r,e,n=()=>({containers:[]})){let f=s(t),o=e?f.get(e):void 0,i=o?o.count>0:!1;return u(()=>{if(!(!e||!r))return t.dispatch("PUSH",e,n),()=>t.dispatch("POP",e,n)},[r,e]),i}export{a as useDocumentOverflowLockedEffect}; |
@@ -1,2 +0,1 @@ | ||
import { type MutableRefObject } from 'react'; | ||
export declare function useDidElementMove(element: MutableRefObject<HTMLElement | null>, enabled?: boolean): boolean; | ||
export declare function useDidElementMove(enabled: boolean, element: HTMLElement | null): boolean; |
@@ -1,1 +0,1 @@ | ||
import{useRef as o}from"react";import{useIsoMorphicEffect as f}from'./use-iso-morphic-effect.js';function p(e,r=!0){let t=o({left:0,top:0});if(f(()=>{let u=e.current;if(!u)return;let l=u.getBoundingClientRect();l&&(t.current=l)},[r]),e.current==null||!r||e.current===document.activeElement)return!1;let n=e.current.getBoundingClientRect();return n.top!==t.current.top||n.left!==t.current.left}export{p as useDidElementMove}; | ||
import{useRef as i}from"react";import{useIsoMorphicEffect as u}from'./use-iso-morphic-effect.js';function s(n,t){let e=i({left:0,top:0});if(u(()=>{if(!t)return;let r=t.getBoundingClientRect();r&&(e.current=r)},[n,t]),t==null||!n||t===document.activeElement)return!1;let o=t.getBoundingClientRect();return o.top!==e.current.top||o.left!==e.current.left}export{s as useDidElementMove}; |
@@ -1,1 +0,1 @@ | ||
export declare function useDocumentEvent<TType extends keyof DocumentEventMap>(type: TType, listener: (ev: DocumentEventMap[TType]) => any, options?: boolean | AddEventListenerOptions): void; | ||
export declare function useDocumentEvent<TType extends keyof DocumentEventMap>(enabled: boolean, type: TType, listener: (ev: DocumentEventMap[TType]) => any, options?: boolean | AddEventListenerOptions): void; |
@@ -1,1 +0,1 @@ | ||
import{useEffect as m}from"react";import{useLatestValue as c}from'./use-latest-value.js';function d(e,r,n){let o=c(r);m(()=>{function t(u){o.current(u)}return document.addEventListener(e,t,n),()=>document.removeEventListener(e,t,n)},[e,n])}export{d as useDocumentEvent}; | ||
import{useEffect as c}from"react";import{useLatestValue as a}from'./use-latest-value.js';function i(t,e,o,n){let u=a(o);c(()=>{if(!t)return;function r(m){u.current(m)}return document.addEventListener(e,r,n),()=>document.removeEventListener(e,r,n)},[t,e,n])}export{i as useDocumentEvent}; |
@@ -1,3 +0,2 @@ | ||
/// <reference types="react" /> | ||
export declare function useElementSize(ref: React.MutableRefObject<HTMLElement | null> | HTMLElement | null, unit?: boolean): { | ||
export declare function useElementSize(element: HTMLElement | null, unit?: boolean): { | ||
width: number; | ||
@@ -4,0 +3,0 @@ height: number; |
@@ -1,1 +0,1 @@ | ||
import{useState as o}from"react";import{useIsoMorphicEffect as h}from'./use-iso-morphic-effect.js';function l(e){if(e===null)return{width:0,height:0};let{width:n,height:t}=e.getBoundingClientRect();return{width:n,height:t}}function m(e,n=!1){let t=e===null?null:"current"in e?e.current:e,[i,u]=o(()=>l(t));return h(()=>{if(!t)return;let r=new ResizeObserver(()=>{u(l(t))});return r.observe(t),()=>{r.disconnect()}},[t]),n?{width:`${i.width}px`,height:`${i.height}px`}:i}export{m as useElementSize}; | ||
import{useMemo as o,useReducer as h}from"react";import{useIsoMorphicEffect as s}from'./use-iso-morphic-effect.js';function f(e){if(e===null)return{width:0,height:0};let{width:t,height:r}=e.getBoundingClientRect();return{width:t,height:r}}function d(e,t=!1){let[r,u]=h(()=>({}),{}),i=o(()=>f(e),[e,r]);return s(()=>{if(!e)return;let n=new ResizeObserver(u);return n.observe(e),()=>{n.disconnect()}},[e]),t?{width:`${i.width}px`,height:`${i.height}px`}:i}export{d as useElementSize}; |
export declare function useFlags(initialFlags?: number): { | ||
flags: number; | ||
setFlag: (flag: number) => void; | ||
addFlag: (flag: number) => void; | ||
@@ -4,0 +5,0 @@ hasFlag: (flag: number) => boolean; |
@@ -1,1 +0,1 @@ | ||
import{useCallback as n,useState as f}from"react";import{useIsMounted as i}from'./use-is-mounted.js';function c(a=0){let[l,r]=f(a),t=i(),o=n(e=>{t.current&&r(u=>u|e)},[l,t]),m=n(e=>!!(l&e),[l]),s=n(e=>{t.current&&r(u=>u&~e)},[r,t]),g=n(e=>{t.current&&r(u=>u^e)},[r]);return{flags:l,addFlag:o,hasFlag:m,removeFlag:s,toggleFlag:g}}export{c as useFlags}; | ||
import{useCallback as r,useState as b}from"react";function c(u=0){let[t,l]=b(u),g=r(e=>l(e),[t]),s=r(e=>l(a=>a|e),[t]),m=r(e=>(t&e)===e,[t]),n=r(e=>l(a=>a&~e),[l]),F=r(e=>l(a=>a^e),[l]);return{flags:t,setFlag:g,addFlag:s,hasFlag:m,removeFlag:n,toggleFlag:F}}export{c as useFlags}; |
@@ -9,2 +9,2 @@ import { type MutableRefObject } from 'react'; | ||
*/ | ||
export declare function useOnDisappear(ref: MutableRefObject<HTMLElement | null> | HTMLElement | null, cb: () => void, enabled?: boolean): void; | ||
export declare function useOnDisappear(enabled: boolean, ref: MutableRefObject<HTMLElement | null> | HTMLElement | null, cb: () => void): void; |
@@ -1,1 +0,1 @@ | ||
import{useEffect as o}from"react";import{disposables as u}from'../utils/disposables.js';import{useLatestValue as c}from'./use-latest-value.js';function m(n,l,s=!0){let i=c(t=>{let e=t.getBoundingClientRect();e.x===0&&e.y===0&&e.width===0&&e.height===0&&l()});o(()=>{if(!s)return;let t=n===null?null:n instanceof HTMLElement?n:n.current;if(!t)return;let e=u();if(typeof ResizeObserver!="undefined"){let r=new ResizeObserver(()=>i.current(t));r.observe(t),e.add(()=>r.disconnect())}if(typeof IntersectionObserver!="undefined"){let r=new IntersectionObserver(()=>i.current(t));r.observe(t),e.add(()=>r.disconnect())}return()=>e.dispose()},[n,i,s])}export{m as useOnDisappear}; | ||
import{useEffect as o}from"react";import{disposables as u}from'../utils/disposables.js';import{useLatestValue as c}from'./use-latest-value.js';function m(s,n,l){let i=c(t=>{let e=t.getBoundingClientRect();e.x===0&&e.y===0&&e.width===0&&e.height===0&&l()});o(()=>{if(!s)return;let t=n===null?null:n instanceof HTMLElement?n:n.current;if(!t)return;let e=u();if(typeof ResizeObserver!="undefined"){let r=new ResizeObserver(()=>i.current(t));r.observe(t),e.add(()=>r.disconnect())}if(typeof IntersectionObserver!="undefined"){let r=new IntersectionObserver(()=>i.current(t));r.observe(t),e.add(()=>r.disconnect())}return()=>e.dispose()},[n,i,s])}export{m as useOnDisappear}; |
@@ -1,6 +0,5 @@ | ||
import { type MutableRefObject } from 'react'; | ||
type Container = MutableRefObject<HTMLElement | null> | HTMLElement | null; | ||
type Container = HTMLElement | null; | ||
type ContainerCollection = Container[] | Set<Container>; | ||
type ContainerInput = Container | ContainerCollection; | ||
export declare function useOutsideClick(containers: ContainerInput | (() => ContainerInput), cb: (event: MouseEvent | PointerEvent | FocusEvent | TouchEvent, target: HTMLElement) => void, enabled?: boolean): void; | ||
export declare function useOutsideClick(enabled: boolean, containers: ContainerInput | (() => ContainerInput), cb: (event: MouseEvent | PointerEvent | FocusEvent | TouchEvent, target: HTMLElement) => void): void; | ||
export {}; |
@@ -1,1 +0,1 @@ | ||
import{useEffect as d,useRef as f}from"react";import{FocusableMode as p,isFocusableElement as C}from'../utils/focus-management.js';import{isMobile as M}from'../utils/platform.js';import{useDocumentEvent as l}from'./use-document-event.js';import{useWindowEvent as T}from'./use-window-event.js';function w(s,m,a=!0){let i=f(!1);d(()=>{requestAnimationFrame(()=>{i.current=a})},[a]);function c(e,r){if(!i.current||e.defaultPrevented)return;let t=r(e);if(t===null||!t.getRootNode().contains(t)||!t.isConnected)return;let E=function u(n){return typeof n=="function"?u(n()):Array.isArray(n)||n instanceof Set?n:[n]}(s);for(let u of E){if(u===null)continue;let n=u instanceof HTMLElement?u:u.current;if(n!=null&&n.contains(t)||e.composed&&e.composedPath().includes(n))return}return!C(t,p.Loose)&&t.tabIndex!==-1&&e.preventDefault(),m(e,t)}let o=f(null);l("pointerdown",e=>{var r,t;i.current&&(o.current=((t=(r=e.composedPath)==null?void 0:r.call(e))==null?void 0:t[0])||e.target)},!0),l("mousedown",e=>{var r,t;i.current&&(o.current=((t=(r=e.composedPath)==null?void 0:r.call(e))==null?void 0:t[0])||e.target)},!0),l("click",e=>{M()||o.current&&(c(e,()=>o.current),o.current=null)},!0),l("touchend",e=>c(e,()=>e.target instanceof HTMLElement?e.target:null),!0),T("blur",e=>c(e,()=>window.document.activeElement instanceof HTMLIFrameElement?window.document.activeElement:null),!0)}export{w as useOutsideClick}; | ||
import{useCallback as T,useRef as d}from"react";import{FocusableMode as y,isFocusableElement as M}from'../utils/focus-management.js';import{isMobile as g}from'../utils/platform.js';import{useDocumentEvent as c}from'./use-document-event.js';import{useIsTopLayer as L}from'./use-is-top-layer.js';import{useLatestValue as b}from'./use-latest-value.js';import{useWindowEvent as P}from'./use-window-event.js';const E=30;function R(p,f,C){let u=L(p,"outside-click"),m=b(C),s=T(function(e,n){if(e.defaultPrevented)return;let r=n(e);if(r===null||!r.getRootNode().contains(r)||!r.isConnected)return;let h=function l(o){return typeof o=="function"?l(o()):Array.isArray(o)||o instanceof Set?o:[o]}(f);for(let l of h)if(l!==null&&(l.contains(r)||e.composed&&e.composedPath().includes(l)))return;return!M(r,y.Loose)&&r.tabIndex!==-1&&e.preventDefault(),m.current(e,r)},[m,f]),i=d(null);c(u,"pointerdown",t=>{var e,n;i.current=((n=(e=t.composedPath)==null?void 0:e.call(t))==null?void 0:n[0])||t.target},!0),c(u,"mousedown",t=>{var e,n;i.current=((n=(e=t.composedPath)==null?void 0:e.call(t))==null?void 0:n[0])||t.target},!0),c(u,"click",t=>{g()||i.current&&(s(t,()=>i.current),i.current=null)},!0);let a=d({x:0,y:0});c(u,"touchstart",t=>{a.current.x=t.touches[0].clientX,a.current.y=t.touches[0].clientY},!0),c(u,"touchend",t=>{let e={x:t.changedTouches[0].clientX,y:t.changedTouches[0].clientY};if(!(Math.abs(e.x-a.current.x)>=E||Math.abs(e.y-a.current.y)>=E))return s(t,()=>t.target instanceof HTMLElement?t.target:null)},!0),P(u,"blur",t=>s(t,()=>window.document.activeElement instanceof HTMLIFrameElement?window.document.activeElement:null),!0)}export{R as useOutsideClick}; |
@@ -1,2 +0,1 @@ | ||
import { type MutableRefObject } from 'react'; | ||
/** | ||
@@ -8,2 +7,2 @@ * The `useRefocusableInput` hook exposes a function to re-focus the input element. | ||
*/ | ||
export declare function useRefocusableInput(ref: MutableRefObject<HTMLInputElement | null>): () => void; | ||
export declare function useRefocusableInput(input: HTMLInputElement | null): () => void; |
@@ -1,1 +0,1 @@ | ||
import{useRef as r}from"react";import{useEvent as c}from'./use-event.js';import{useEventListener as i}from'./use-event-listener.js';function f(l){let n=r({value:"",selectionStart:null,selectionEnd:null});return i(l.current,"blur",e=>{let t=e.target;t instanceof HTMLInputElement&&(n.current={value:t.value,selectionStart:t.selectionStart,selectionEnd:t.selectionEnd})}),c(()=>{let e=l.current;if(document.activeElement!==e&&e instanceof HTMLInputElement&&e.isConnected){if(e.focus({preventScroll:!0}),e.value!==n.current.value)e.setSelectionRange(e.value.length,e.value.length);else{let{selectionStart:t,selectionEnd:u}=n.current;t!==null&&u!==null&&e.setSelectionRange(t,u)}n.current={value:"",selectionStart:null,selectionEnd:null}}})}export{f as useRefocusableInput}; | ||
import{useRef as r}from"react";import{useEvent as u}from'./use-event.js';import{useEventListener as o}from'./use-event-listener.js';function i(e){let n=r({value:"",selectionStart:null,selectionEnd:null});return o(e,"blur",l=>{let t=l.target;t instanceof HTMLInputElement&&(n.current={value:t.value,selectionStart:t.selectionStart,selectionEnd:t.selectionEnd})}),u(()=>{if(document.activeElement!==e&&e instanceof HTMLInputElement&&e.isConnected){if(e.focus({preventScroll:!0}),e.value!==n.current.value)e.setSelectionRange(e.value.length,e.value.length);else{let{selectionStart:l,selectionEnd:t}=n.current;l!==null&&t!==null&&e.setSelectionRange(l,t)}n.current={value:"",selectionStart:null,selectionEnd:null}}})}export{i as useRefocusableInput}; |
@@ -1,5 +0,4 @@ | ||
import { type MutableRefObject } from 'react'; | ||
export declare function useResolveButtonType<TTag>(props: { | ||
type?: string; | ||
as?: TTag; | ||
}, ref: MutableRefObject<HTMLElement | null>): string | undefined; | ||
}, element: HTMLElement | null): string | undefined; |
@@ -1,1 +0,1 @@ | ||
import{useState as o}from"react";import{useIsoMorphicEffect as r}from'./use-iso-morphic-effect.js';function i(t){var n;if(t.type)return t.type;let e=(n=t.as)!=null?n:"button";if(typeof e=="string"&&e.toLowerCase()==="button")return"button"}function T(t,e){let[n,u]=o(()=>i(t));return r(()=>{u(i(t))},[t.type,t.as]),r(()=>{n||e.current&&e.current instanceof HTMLButtonElement&&!e.current.hasAttribute("type")&&u("button")},[n,e]),n}export{T as useResolveButtonType}; | ||
import{useMemo as a}from"react";function e(t,u){return a(()=>{var n;if(t.type)return t.type;let r=(n=t.as)!=null?n:"button";if(typeof r=="string"&&r.toLowerCase()==="button"||(u==null?void 0:u.tagName)==="BUTTON"&&!u.hasAttribute("type"))return"button"},[t.type,t.as,u])}export{e as useResolveButtonType}; |
import React, { type MutableRefObject } from 'react'; | ||
export declare function useRootContainers({ defaultContainers, portals, mainTreeNodeRef: _mainTreeNodeRef, }?: { | ||
export declare function useRootContainers({ defaultContainers, portals, mainTreeNode, }?: { | ||
defaultContainers?: (HTMLElement | null | MutableRefObject<HTMLElement | null>)[]; | ||
portals?: MutableRefObject<HTMLElement[]>; | ||
mainTreeNodeRef?: MutableRefObject<HTMLElement | null>; | ||
mainTreeNode?: HTMLElement | null; | ||
}): { | ||
resolveContainers: () => HTMLElement[]; | ||
contains: (element: HTMLElement) => boolean; | ||
mainTreeNodeRef: React.MutableRefObject<HTMLElement | null>; | ||
MainTreeNode: () => React.JSX.Element | null; | ||
}; | ||
export declare function useMainTreeNode(): { | ||
mainTreeNodeRef: React.MutableRefObject<HTMLElement | null>; | ||
MainTreeNode: () => React.JSX.Element; | ||
}; | ||
/** | ||
* A provider for the main tree node. | ||
* | ||
* When a component is rendered in a `Portal`, it is no longer part of the main | ||
* tree. This provider helps to find the main tree node and pass it along to the | ||
* components that need it. | ||
* | ||
* The main tree node is used for features such as outside click behavior, where | ||
* we allow clicks in 3rd party containers, but not in the parent of the "main | ||
* tree". | ||
* | ||
* In case of a `Popover`, we can use the `PopoverButton` as a marker in the | ||
* "main tree", the `PopoverPanel` can't be used because it could be rendered in | ||
* a `Portal` (e.g. when using the `anchor` props). | ||
* | ||
* However, we can't use the `PopoverButton` when it's nested inside of another | ||
* `Popover`'s `PopoverPanel` component if the parent `PopoverPanel` is | ||
* rendered in a `Portal`. | ||
* | ||
* This is where the `MainTreeProvider` comes in. It will find the "main tree" | ||
* node and pass it on. The top-level `PopoverButton` will be used as a marker | ||
* in the "main tree" and nested `Popover` will use this button as well. | ||
*/ | ||
export declare function MainTreeProvider({ children, node, }: { | ||
children: React.ReactNode; | ||
node?: HTMLElement | null; | ||
}): React.JSX.Element; | ||
/** | ||
* Get the main tree node from context or fallback to the optionally provided node. | ||
*/ | ||
export declare function useMainTreeNode(fallbackMainTreeNode?: HTMLElement | null): HTMLElement | null; |
@@ -1,1 +0,1 @@ | ||
import m,{useMemo as d,useRef as M}from"react";import{Hidden as H,HiddenFeatures as T}from'../internal/hidden.js';import{useEvent as E}from'./use-event.js';import{useOwnerDocument as b}from'./use-owner.js';function j({defaultContainers:o=[],portals:r,mainTreeNodeRef:u}={}){var f;let t=M((f=u==null?void 0:u.current)!=null?f:null),l=b(t),c=E(()=>{var i,s,a;let n=[];for(let e of o)e!==null&&(e instanceof HTMLElement?n.push(e):"current"in e&&e.current instanceof HTMLElement&&n.push(e.current));if(r!=null&&r.current)for(let e of r.current)n.push(e);for(let e of(i=l==null?void 0:l.querySelectorAll("html > *, body > *"))!=null?i:[])e!==document.body&&e!==document.head&&e instanceof HTMLElement&&e.id!=="headlessui-portal-root"&&(e.contains(t.current)||e.contains((a=(s=t.current)==null?void 0:s.getRootNode())==null?void 0:a.host)||n.some(L=>e.contains(L))||n.push(e));return n});return{resolveContainers:c,contains:E(n=>c().some(i=>i.contains(n))),mainTreeNodeRef:t,MainTreeNode:d(()=>function(){return u!=null?null:m.createElement(H,{features:T.Hidden,ref:t})},[t,u])}}function y(){let o=M(null);return{mainTreeNodeRef:o,MainTreeNode:d(()=>function(){return m.createElement(H,{features:T.Hidden,ref:o})},[o])}}export{y as useMainTreeNode,j as useRootContainers}; | ||
import f,{createContext as M,useContext as d,useState as H}from"react";import{Hidden as E,HiddenFeatures as T}from'../internal/hidden.js';import{getOwnerDocument as L}from'../utils/owner.js';import{useEvent as s}from'./use-event.js';import{useOwnerDocument as h}from'./use-owner.js';function R({defaultContainers:l=[],portals:n,mainTreeNode:o}={}){let r=h(o),u=s(()=>{var i,c;let t=[];for(let e of l)e!==null&&(e instanceof HTMLElement?t.push(e):"current"in e&&e.current instanceof HTMLElement&&t.push(e.current));if(n!=null&&n.current)for(let e of n.current)t.push(e);for(let e of(i=r==null?void 0:r.querySelectorAll("html > *, body > *"))!=null?i:[])e!==document.body&&e!==document.head&&e instanceof HTMLElement&&e.id!=="headlessui-portal-root"&&(o&&(e.contains(o)||e.contains((c=o==null?void 0:o.getRootNode())==null?void 0:c.host))||t.some(m=>e.contains(m))||t.push(e));return t});return{resolveContainers:u,contains:s(t=>u().some(i=>i.contains(t)))}}let a=M(null);function O({children:l,node:n}){let[o,r]=H(null),u=b(n!=null?n:o);return f.createElement(a.Provider,{value:u},l,u===null&&f.createElement(E,{features:T.Hidden,ref:t=>{var i,c;if(t){for(let e of(c=(i=L(t))==null?void 0:i.querySelectorAll("html > *, body > *"))!=null?c:[])if(e!==document.body&&e!==document.head&&e instanceof HTMLElement&&e!=null&&e.contains(t)){r(e);break}}}}))}function b(l=null){var n;return(n=d(a))!=null?n:l}export{O as MainTreeProvider,b as useMainTreeNode,R as useRootContainers}; |
@@ -1,1 +0,1 @@ | ||
import{useRef as t}from"react";import{useWindowEvent as a}from'./use-window-event.js';var s=(r=>(r[r.Forwards=0]="Forwards",r[r.Backwards=1]="Backwards",r))(s||{});function n(){let e=t(0);return a("keydown",o=>{o.key==="Tab"&&(e.current=o.shiftKey?1:0)},!0),e}export{s as Direction,n as useTabDirection}; | ||
import{useRef as o}from"react";import{useWindowEvent as t}from'./use-window-event.js';var a=(r=>(r[r.Forwards=0]="Forwards",r[r.Backwards=1]="Backwards",r))(a||{});function u(){let e=o(0);return t(!0,"keydown",r=>{r.key==="Tab"&&(e.current=r.shiftKey?1:0)},!0),e}export{a as Direction,u as useTabDirection}; |
@@ -1,19 +0,12 @@ | ||
import { type MutableRefObject } from 'react'; | ||
interface TransitionArgs { | ||
container: MutableRefObject<HTMLElement | null>; | ||
classes: MutableRefObject<{ | ||
base: string[]; | ||
enter: string[]; | ||
enterFrom: string[]; | ||
enterTo: string[]; | ||
leave: string[]; | ||
leaveFrom: string[]; | ||
leaveTo: string[]; | ||
entered: string[]; | ||
}>; | ||
direction: 'enter' | 'leave' | 'idle'; | ||
onStart: MutableRefObject<(direction: TransitionArgs['direction']) => void>; | ||
onStop: MutableRefObject<(direction: TransitionArgs['direction']) => void>; | ||
} | ||
export declare function useTransition({ container, direction, classes, onStart, onStop }: TransitionArgs): void; | ||
type TransitionData = { | ||
closed?: boolean; | ||
enter?: boolean; | ||
leave?: boolean; | ||
transition?: boolean; | ||
}; | ||
export declare function transitionDataAttributes(data: TransitionData): Record<string, string>; | ||
export declare function useTransition(enabled: boolean, element: HTMLElement | null, show: boolean, events?: { | ||
start?(show: boolean): void; | ||
end?(show: boolean): void; | ||
}): [visible: boolean, data: TransitionData]; | ||
export {}; |
@@ -1,1 +0,2 @@ | ||
import{useRef as u}from"react";import{transition as f}from'../components/transition/utils/transition.js';import{useDisposables as c}from'./use-disposables.js';import{useIsMounted as d}from'./use-is-mounted.js';import{useIsoMorphicEffect as m}from'./use-iso-morphic-effect.js';function v({container:n,direction:e,classes:i,onStart:s,onStop:o}){let a=d(),t=c(),l=u(!1);m(()=>{let r=n.current;if(r&&e!=="idle"&&a.current)return s.current(e),t.add(f(r,{direction:e,classes:i.current,inFlight:l,done(){o.current(e)}})),t.dispose},[e])}export{v as useTransition}; | ||
var T;import{useRef as c,useState as S}from"react";import{disposables as m}from'../utils/disposables.js';import{useDisposables as g}from'./use-disposables.js';import{useFlags as E}from'./use-flags.js';import{useIsoMorphicEffect as y}from'./use-iso-morphic-effect.js';typeof process!="undefined"&&typeof globalThis!="undefined"&&((T=process==null?void 0:process.env)==null?void 0:T["NODE_ENV"])==="test"&&typeof Element.prototype.getAnimations=="undefined"&&(Element.prototype.getAnimations=function(){return console.warn(["Headless UI has polyfilled `Element.prototype.getAnimations` for your tests.","Please install a proper polyfill e.g. `jsdom-testing-mocks`, to silence these warnings.","","Example usage:","```js","import { mockAnimationsApi } from 'jsdom-testing-mocks'","mockAnimationsApi()","```"].join(` | ||
`)),[]});var A=(r=>(r[r.None=0]="None",r[r.Closed=1]="Closed",r[r.Enter=2]="Enter",r[r.Leave=4]="Leave",r))(A||{});function H(e){let n={};for(let t in e)e[t]===!0&&(n[`data-${t}`]="");return n}function R(e,n,t,i){let[r,o]=S(t),{hasFlag:s,addFlag:a,removeFlag:l}=E(e&&r?3:0),u=c(!1),f=c(!1),b=g();return y(()=>{var d;if(e){if(t&&o(!0),!n){t&&a(3);return}return(d=i==null?void 0:i.start)==null||d.call(i,t),L(n,{inFlight:u,prepare(){f.current?f.current=!1:f.current=u.current,u.current=!0,!f.current&&(t?(a(3),l(4)):(a(4),l(2)))},run(){f.current?t?(l(3),a(4)):(l(4),a(3)):t?l(1):a(1)},done(){var p;f.current&&typeof n.getAnimations=="function"&&n.getAnimations().length>0||(u.current=!1,l(7),t||o(!1),(p=i==null?void 0:i.end)==null||p.call(i,t))}})}},[e,t,n,b]),e?[r,{closed:s(1),enter:s(2),leave:s(4),transition:s(2)||s(4)}]:[t,{closed:void 0,enter:void 0,leave:void 0,transition:void 0}]}function L(e,{prepare:n,run:t,done:i,inFlight:r}){let o=m();return M(e,{prepare:n,inFlight:r}),o.nextFrame(()=>{t(),o.requestAnimationFrame(()=>{o.add(C(e,i))})}),o.dispose}function C(e,n){var o,s;let t=m();if(!e)return t.dispose;let i=!1;t.add(()=>{i=!0});let r=(s=(o=e.getAnimations)==null?void 0:o.call(e).filter(a=>a instanceof CSSTransition))!=null?s:[];return r.length===0?(n(),t.dispose):(Promise.allSettled(r.map(a=>a.finished)).then(()=>{i||n()}),t.dispose)}function M(e,{inFlight:n,prepare:t}){if(n!=null&&n.current){t();return}let i=e.style.transition;e.style.transition="none",t(),e.offsetHeight,e.style.transition=i}export{H as transitionDataAttributes,R as useTransition}; |
type AcceptNode = (node: HTMLElement) => typeof NodeFilter.FILTER_ACCEPT | typeof NodeFilter.FILTER_SKIP | typeof NodeFilter.FILTER_REJECT; | ||
export declare function useTreeWalker({ container, accept, walk, enabled, }: { | ||
export declare function useTreeWalker(enabled: boolean, { container, accept, walk, }: { | ||
container: HTMLElement | null; | ||
accept: AcceptNode; | ||
walk(node: HTMLElement): void; | ||
enabled?: boolean; | ||
}): void; | ||
export {}; |
@@ -1,1 +0,1 @@ | ||
import{useEffect as m,useRef as E}from"react";import{getOwnerDocument as T}from'../utils/owner.js';import{useIsoMorphicEffect as N}from'./use-iso-morphic-effect.js';function F({container:e,accept:t,walk:r,enabled:c=!0}){let o=E(t),l=E(r);m(()=>{o.current=t,l.current=r},[t,r]),N(()=>{if(!e||!c)return;let n=T(e);if(!n)return;let f=o.current,p=l.current,d=Object.assign(i=>f(i),{acceptNode:f}),u=n.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,d,!1);for(;u.nextNode();)p(u.currentNode)},[e,c,o,l])}export{F as useTreeWalker}; | ||
import{useEffect as T,useRef as E}from"react";import{getOwnerDocument as d}from'../utils/owner.js';import{useIsoMorphicEffect as N}from'./use-iso-morphic-effect.js';function F(c,{container:e,accept:t,walk:r}){let o=E(t),l=E(r);T(()=>{o.current=t,l.current=r},[t,r]),N(()=>{if(!e||!c)return;let n=d(e);if(!n)return;let f=o.current,p=l.current,i=Object.assign(m=>f(m),{acceptNode:f}),u=n.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,i,!1);for(;u.nextNode();)p(u.currentNode)},[e,c,o,l])}export{F as useTreeWalker}; |
@@ -1,1 +0,1 @@ | ||
export declare function useWindowEvent<TType extends keyof WindowEventMap>(type: TType, listener: (ev: WindowEventMap[TType]) => any, options?: boolean | AddEventListenerOptions): void; | ||
export declare function useWindowEvent<TType extends keyof WindowEventMap>(enabled: boolean, type: TType, listener: (ev: WindowEventMap[TType]) => any, options?: boolean | AddEventListenerOptions): void; |
@@ -1,1 +0,1 @@ | ||
import{useEffect as d}from"react";import{useLatestValue as a}from'./use-latest-value.js';function s(e,r,n){let o=a(r);d(()=>{function t(i){o.current(i)}return window.addEventListener(e,t,n),()=>window.removeEventListener(e,t,n)},[e,n])}export{s as useWindowEvent}; | ||
import{useEffect as a}from"react";import{useLatestValue as f}from'./use-latest-value.js';function s(t,e,o,n){let i=f(o);a(()=>{if(!t)return;function r(d){i.current(d)}return window.addEventListener(e,r,n),()=>window.removeEventListener(e,r,n)},[t,e,n])}export{s as useWindowEvent}; |
@@ -1,1 +0,1 @@ | ||
import r,{createContext as n,useContext as i}from"react";let e=n(()=>{});function l(){return i(e)}function u({value:o,children:t}){return r.createElement(e.Provider,{value:o},t)}export{u as CloseProvider,l as useClose}; | ||
"use client";import r,{createContext as n,useContext as i}from"react";let e=n(()=>{});function u(){return i(e)}function C({value:t,children:o}){return r.createElement(e.Provider,{value:t},o)}export{C as CloseProvider,u as useClose}; |
@@ -7,6 +7,2 @@ import { type InnerProps } from '@floating-ui/react'; | ||
/** | ||
* The strategy to use when positioning the panel. Defaults to `absolute`. | ||
*/ | ||
strategy: 'absolute' | 'fixed'; | ||
/** | ||
* The `gap` is the space between the trigger and the panel. | ||
@@ -24,3 +20,3 @@ */ | ||
}; | ||
export type AnchorProps = Partial<BaseAnchorProps & { | ||
export type AnchorProps = false | (`${Placement}` | `${Placement} ${Align}`) | Partial<BaseAnchorProps & { | ||
/** | ||
@@ -32,3 +28,3 @@ * The `to` value defines which side of the trigger the panel should be placed on and its | ||
}>; | ||
export type AnchorPropsWithSelection = Partial<BaseAnchorProps & { | ||
export type AnchorPropsWithSelection = false | (`${Placement | 'selection'}` | `${Placement | 'selection'} ${Align}`) | Partial<BaseAnchorProps & { | ||
/** | ||
@@ -46,2 +42,3 @@ * The `to` value defines which side of the trigger the panel should be placed on and its | ||
}>; | ||
export declare function useResolvedAnchor<T extends AnchorProps | AnchorPropsWithSelection>(anchor?: T): Exclude<T, boolean | string> | null; | ||
export declare function useFloatingReference(): ((node: import("@floating-ui/react-dom").ReferenceType | null) => void) & ((node: any) => void); | ||
@@ -52,3 +49,3 @@ export declare function useFloatingReferenceProps(): (userProps?: React.HTMLProps<Element> | undefined) => Record<string, unknown>; | ||
}; | ||
export declare function useFloatingPanel(placement?: AnchorPropsWithSelection & InternalFloatingPanelProps): readonly [((node: HTMLElement | null) => void) & ((node: HTMLElement | null) => void), React.CSSProperties | undefined]; | ||
export declare function useFloatingPanel(placement?: (AnchorPropsWithSelection & InternalFloatingPanelProps) | null): readonly [((node: HTMLElement | null) => void) & ((node: HTMLElement | null) => void), React.CSSProperties | undefined]; | ||
export declare function FloatingProvider({ children, enabled, }: { | ||
@@ -55,0 +52,0 @@ children: React.ReactNode; |
@@ -1,1 +0,1 @@ | ||
import{autoUpdate as ee,flip as te,inner as ne,offset as le,shift as re,size as oe,useFloating as ie,useInnerOffset as se,useInteractions as ae}from"@floating-ui/react";import*as _ from"react";import{createContext as z,useCallback as ue,useContext as x,useMemo as E,useRef as pe,useState as I}from"react";import{useDisposables as fe}from'../hooks/use-disposables.js';import{useEvent as q}from'../hooks/use-event.js';import{useIsoMorphicEffect as w}from'../hooks/use-iso-morphic-effect.js';let h=z({styles:void 0,setReference:()=>{},setFloating:()=>{},getReferenceProps:()=>({}),getFloatingProps:()=>({}),slot:{}});h.displayName="FloatingContext";let L=z(null);L.displayName="PlacementContext";function xe(){return x(h).setReference}function Fe(){return x(h).getReferenceProps}function be(){let{getFloatingProps:e,slot:t}=x(h);return ue((...n)=>Object.assign({},e(...n),{"data-anchor":t.anchor}),[e,t])}function Me(e){let t=x(L),n=E(()=>e,[JSON.stringify(e,typeof HTMLElement!="undefined"?(s,a)=>a instanceof HTMLElement?a.outerHTML:a:void 0)]);w(()=>{t==null||t(n!=null?n:null)},[t,n]);let l=x(h);return E(()=>[l.setFloating,l.styles],[l.setFloating,l.styles])}let D=4;function Re({children:e,enabled:t=!0}){let[n,l]=I(null),[s,a]=I(0),F=pe(null),[g,i]=I(null);ce(g);let r=t&&n!==null&&g!==null,{to:y="bottom",gap:A=0,offset:b=0,padding:u=0,inner:m,strategy:M="absolute"}=ge(n,g),[o,p="center"]=y.split(" ");w(()=>{r&&a(0)},[r]);let{refs:R,floatingStyles:C,context:v}=ie({open:r,placement:o==="selection"?p==="center"?"bottom":`bottom-${p}`:p==="center"?`${o}`:`${o}-${p}`,strategy:M,transform:!1,middleware:[le({mainAxis:o==="selection"?0:A,crossAxis:b}),re({padding:u}),o!=="selection"&&te(),o==="selection"&&m?ne({...m,padding:u,overflowRef:F,offset:s,minItemsVisible:D,referenceOverflowThreshold:u,onFallbackChange(d){var N,U;if(!d)return;let f=v.elements.floating;if(!f)return;let T=parseFloat(getComputedStyle(f).scrollPaddingBottom)||0,S=Math.min(D,f.childElementCount),O=0,k=0;for(let c of(U=(N=v.elements.floating)==null?void 0:N.childNodes)!=null?U:[])if(c instanceof HTMLElement){let P=c.offsetTop,W=P+c.clientHeight+T,$=f.scrollTop,j=$+f.clientHeight;if(P>=$&&W<=j)S--;else{k=Math.max(0,Math.min(W,j)-Math.max(P,$)),O=c.clientHeight;break}}S>=1&&a(c=>{let P=O*S-k+T;return c>=P?c:P})}}):null,oe({apply({availableWidth:d,availableHeight:f,elements:T}){Object.assign(T.floating.style,{maxWidth:`${d-u}px`,maxHeight:`${f-u}px`})}})].filter(Boolean),whileElementsMounted:ee}),[H=o,B=p]=v.placement.split("-");o==="selection"&&(H="selection");let K=E(()=>({anchor:[H,B].filter(Boolean).join(" ")}),[H,B]),Q=se(v,{overflowRef:F,onChange:a}),{getReferenceProps:X,getFloatingProps:Y}=ae([Q]),Z=q(d=>{i(d),R.setFloating(d)});return _.createElement(L.Provider,{value:l},_.createElement(h.Provider,{value:{setFloating:Z,setReference:R.setReference,styles:r?C:{},getReferenceProps:X,getFloatingProps:Y,slot:K}},e))}function ce(e){w(()=>{if(!e)return;let t=new MutationObserver(()=>{let n=e.style.maxHeight;parseFloat(n)!==parseInt(n)&&(e.style.maxHeight=`${Math.ceil(parseFloat(n))}px`)});return t.observe(e,{attributes:!0,attributeFilter:["style"]}),()=>{t.disconnect()}},[e])}function ge(e,t){let n=V(e==null?void 0:e.gap,t),l=V(e==null?void 0:e.offset,t),s=V(e==null?void 0:e.padding,t);return{...e,gap:n,offset:l,padding:s}}function V(e,t,n=void 0){let l=fe(),s=q((i,r)=>{if(i==null)return[n,null];if(typeof i=="number")return[i,null];if(typeof i=="string"){if(!r)return[n,null];let y=G(i,r);return[y,A=>{let b=J(i);{let u=b.map(m=>window.getComputedStyle(r).getPropertyValue(m));l.requestAnimationFrame(function m(){l.nextFrame(m);let M=!1;for(let[p,R]of b.entries()){let C=window.getComputedStyle(r).getPropertyValue(R);if(u[p]!==C){u[p]=C,M=!0;break}}if(!M)return;let o=G(i,r);y!==o&&(A(o),y=o)})}return l.dispose}]}return[n,null]}),a=E(()=>s(e,t)[0],[e,t]),[F=a,g]=I();return w(()=>{let[i,r]=s(e,t);if(g(i),!!r)return r(g)},[e,t]),F}function J(e){let t=/var\((.*)\)/.exec(e);if(t){let n=t[1].indexOf(",");if(n===-1)return[t[1]];let l=t[1].slice(0,n).trim(),s=t[1].slice(n+1).trim();return s?[l,...J(s)]:[l]}return[]}function G(e,t){let n=document.createElement("div");t.appendChild(n),n.style.setProperty("margin-top","0px","important"),n.style.setProperty("margin-top",e,"important");let l=parseFloat(window.getComputedStyle(n).marginTop)||0;return t.removeChild(n),l}export{Re as FloatingProvider,Me as useFloatingPanel,be as useFloatingPanelProps,xe as useFloatingReference,Fe as useFloatingReferenceProps}; | ||
import{autoUpdate as Z,flip as ee,inner as te,offset as ne,shift as le,size as re,useFloating as oe,useInnerOffset as ie,useInteractions as se}from"@floating-ui/react";import*as j from"react";import{createContext as _,useCallback as ae,useContext as R,useMemo as v,useRef as ue,useState as E}from"react";import{useDisposables as fe}from'../hooks/use-disposables.js';import{useEvent as z}from'../hooks/use-event.js';import{useIsoMorphicEffect as A}from'../hooks/use-iso-morphic-effect.js';let y=_({styles:void 0,setReference:()=>{},setFloating:()=>{},getReferenceProps:()=>({}),getFloatingProps:()=>({}),slot:{}});y.displayName="FloatingContext";let S=_(null);S.displayName="PlacementContext";function xe(e){return v(()=>e?typeof e=="string"?{to:e}:e:null,[e])}function ye(){return R(y).setReference}function Fe(){return R(y).getReferenceProps}function be(){let{getFloatingProps:e,slot:t}=R(y);return ae((...n)=>Object.assign({},e(...n),{"data-anchor":t.anchor}),[e,t])}function Re(e=null){e===!1&&(e=null),typeof e=="string"&&(e={to:e});let t=R(S),n=v(()=>e,[JSON.stringify(e,typeof HTMLElement!="undefined"?(r,o)=>o instanceof HTMLElement?o.outerHTML:o:void 0)]);A(()=>{t==null||t(n!=null?n:null)},[t,n]);let l=R(y);return v(()=>[l.setFloating,e?l.styles:{}],[l.setFloating,e,l.styles])}let q=4;function ve({children:e,enabled:t=!0}){let[n,l]=E(null),[r,o]=E(0),c=ue(null),[u,s]=E(null);pe(u);let i=t&&n!==null&&u!==null,{to:F="bottom",gap:C=0,offset:M=0,padding:p=0,inner:P}=ce(n,u),[a,f="center"]=F.split(" ");A(()=>{i&&o(0)},[i]);let{refs:b,floatingStyles:w,context:g}=oe({open:i,placement:a==="selection"?f==="center"?"bottom":`bottom-${f}`:f==="center"?`${a}`:`${a}-${f}`,strategy:"absolute",transform:!1,middleware:[ne({mainAxis:a==="selection"?0:C,crossAxis:M}),le({padding:p}),a!=="selection"&&ee({padding:p}),a==="selection"&&P?te({...P,padding:p,overflowRef:c,offset:r,minItemsVisible:q,referenceOverflowThreshold:p,onFallbackChange(h){var O,W;if(!h)return;let d=g.elements.floating;if(!d)return;let T=parseFloat(getComputedStyle(d).scrollPaddingBottom)||0,$=Math.min(q,d.childElementCount),B=0,N=0;for(let m of(W=(O=g.elements.floating)==null?void 0:O.childNodes)!=null?W:[])if(m instanceof HTMLElement){let x=m.offsetTop,k=x+m.clientHeight+T,H=d.scrollTop,U=H+d.clientHeight;if(x>=H&&k<=U)$--;else{N=Math.max(0,Math.min(k,U)-Math.max(x,H)),B=m.clientHeight;break}}$>=1&&o(m=>{let x=B*$-N+T;return m>=x?m:x})}}):null,re({padding:p,apply({availableWidth:h,availableHeight:d,elements:T}){Object.assign(T.floating.style,{overflow:"auto",maxWidth:`${h}px`,maxHeight:`min(var(--anchor-max-height, 100vh), ${d}px)`})}})].filter(Boolean),whileElementsMounted:Z}),[I=a,V=f]=g.placement.split("-");a==="selection"&&(I="selection");let G=v(()=>({anchor:[I,V].filter(Boolean).join(" ")}),[I,V]),K=ie(g,{overflowRef:c,onChange:o}),{getReferenceProps:Q,getFloatingProps:X}=se([K]),Y=z(h=>{s(h),b.setFloating(h)});return j.createElement(S.Provider,{value:l},j.createElement(y.Provider,{value:{setFloating:Y,setReference:b.setReference,styles:w,getReferenceProps:Q,getFloatingProps:X,slot:G}},e))}function pe(e){A(()=>{if(!e)return;let t=new MutationObserver(()=>{let n=window.getComputedStyle(e).maxHeight,l=parseFloat(n);if(isNaN(l))return;let r=parseInt(n);isNaN(r)||l!==r&&(e.style.maxHeight=`${Math.ceil(l)}px`)});return t.observe(e,{attributes:!0,attributeFilter:["style"]}),()=>{t.disconnect()}},[e])}function ce(e,t){var o,c,u;let n=L((o=e==null?void 0:e.gap)!=null?o:"var(--anchor-gap, 0)",t),l=L((c=e==null?void 0:e.offset)!=null?c:"var(--anchor-offset, 0)",t),r=L((u=e==null?void 0:e.padding)!=null?u:"var(--anchor-padding, 0)",t);return{...e,gap:n,offset:l,padding:r}}function L(e,t,n=void 0){let l=fe(),r=z((s,i)=>{if(s==null)return[n,null];if(typeof s=="number")return[s,null];if(typeof s=="string"){if(!i)return[n,null];let F=J(s,i);return[F,C=>{let M=D(s);{let p=M.map(P=>window.getComputedStyle(i).getPropertyValue(P));l.requestAnimationFrame(function P(){l.nextFrame(P);let a=!1;for(let[b,w]of M.entries()){let g=window.getComputedStyle(i).getPropertyValue(w);if(p[b]!==g){p[b]=g,a=!0;break}}if(!a)return;let f=J(s,i);F!==f&&(C(f),F=f)})}return l.dispose}]}return[n,null]}),o=v(()=>r(e,t)[0],[e,t]),[c=o,u]=E();return A(()=>{let[s,i]=r(e,t);if(u(s),!!i)return i(u)},[e,t]),c}function D(e){let t=/var\((.*)\)/.exec(e);if(t){let n=t[1].indexOf(",");if(n===-1)return[t[1]];let l=t[1].slice(0,n).trim(),r=t[1].slice(n+1).trim();return r?[l,...D(r)]:[l]}return[]}function J(e,t){let n=document.createElement("div");t.appendChild(n),n.style.setProperty("margin-top","0px","important"),n.style.setProperty("margin-top",e,"important");let l=parseFloat(window.getComputedStyle(n).marginTop)||0;return t.removeChild(n),l}export{ve as FloatingProvider,Re as useFloatingPanel,be as useFloatingPanelProps,ye as useFloatingReference,Fe as useFloatingReferenceProps,xe as useResolvedAnchor}; |
import type { ElementType, Ref } from 'react'; |
import type { Props } from '../types.js'; |
import { type HasDisplayName, type RefProp } from '../utils/render.js'; |
declare let DEFAULT_VISUALLY_HIDDEN_TAG: "div"; |
declare let DEFAULT_VISUALLY_HIDDEN_TAG: "span"; |
export declare enum HiddenFeatures { |
@@ -6,0 +6,0 @@ None = 1, |
@@ -1,1 +0,1 @@ |
import{forwardRefWithAs as i,render as p}from'../utils/render.js';let a="div";var s=(e=>(e[e.None=1]="None",e[e.Focusable=2]="Focusable",e[e.Hidden=4]="Hidden",e))(s||{});function l(t,r){var n;let{features:d=1,...e}=t,o={ref:r,"aria-hidden":(d&2)===2?!0:(n=e["aria-hidden"])!=null?n:void 0,hidden:(d&4)===4?!0:void 0,style:{position:"fixed",top:1,left:1,width:1,height:0,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0",...(d&4)===4&&(d&2)!==2&&{display:"none"}}};return p({ourProps:o,theirProps:e,slot:{},defaultTag:a,name:"Hidden"})}let T=i(l);export{T as Hidden,s as HiddenFeatures}; |
import{forwardRefWithAs as i,render as p}from'../utils/render.js';let a="span";var s=(e=>(e[e.None=1]="None",e[e.Focusable=2]="Focusable",e[e.Hidden=4]="Hidden",e))(s||{});function l(t,r){var n;let{features:d=1,...e}=t,o={ref:r,"aria-hidden":(d&2)===2?!0:(n=e["aria-hidden"])!=null?n:void 0,hidden:(d&4)===4?!0:void 0,style:{position:"fixed",top:1,left:1,width:1,height:0,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0",...(d&4)===4&&(d&2)!==2&&{display:"none"}}};return p({ourProps:o,theirProps:e,slot:{},defaultTag:a,name:"Hidden"})}let T=i(l);export{T as Hidden,s as HiddenFeatures}; |
@@ -1,2 +0,2 @@ | ||
import { type ReactElement, type ReactNode } from 'react'; | ||
import React, { type ReactElement, type ReactNode } from 'react'; | ||
export declare enum State { | ||
@@ -14,2 +14,5 @@ Open = 1, | ||
export declare function OpenClosedProvider({ value, children }: Props): ReactElement; | ||
export declare function ResetOpenClosedProvider({ children }: { | ||
children: React.ReactNode; | ||
}): ReactElement; | ||
export {}; |
@@ -1,1 +0,1 @@ | ||
import t,{createContext as l,useContext as p}from"react";let n=l(null);n.displayName="OpenClosedContext";var d=(e=>(e[e.Open=1]="Open",e[e.Closed=2]="Closed",e[e.Closing=4]="Closing",e[e.Opening=8]="Opening",e))(d||{});function u(){return p(n)}function s({value:o,children:r}){return t.createElement(n.Provider,{value:o},r)}export{s as OpenClosedProvider,d as State,u as useOpenClosed}; | ||
import r,{createContext as l,useContext as d}from"react";let n=l(null);n.displayName="OpenClosedContext";var i=(e=>(e[e.Open=1]="Open",e[e.Closed=2]="Closed",e[e.Closing=4]="Closing",e[e.Opening=8]="Opening",e))(i||{});function u(){return d(n)}function c({value:o,children:t}){return r.createElement(n.Provider,{value:o},t)}function s({children:o}){return r.createElement(n.Provider,{value:null},o)}export{c as OpenClosedProvider,s as ResetOpenClosedProvider,i as State,u as useOpenClosed}; |
import type { JSXElementConstructor, ReactElement, ReactNode } from 'react'; | ||
export type ReactTag = keyof JSX.IntrinsicElements | JSXElementConstructor<any>; | ||
declare let __: "1D45E01E-AF44-47C4-988A-19A94EBAF55C"; | ||
export type __ = typeof __; | ||
export type Expand<T> = T extends infer O ? { | ||
@@ -21,7 +19,3 @@ [K in keyof O]: O[K]; | ||
export type Props<TTag extends ReactTag, TSlot = {}, TOmittableProps extends PropertyKey = never, Overrides = {}> = CleanProps<TTag, TOmittableProps | keyof Overrides> & OurProps<TTag, TSlot> & ClassNameOverride<TTag, TSlot> & Overrides; | ||
type Without<T, U> = { | ||
[P in Exclude<keyof T, keyof U>]?: never; | ||
}; | ||
export type XOR<T, U> = T | U extends __ ? never : T extends __ ? U : U extends __ ? T : T | U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U; | ||
export type EnsureArray<T> = T extends any[] ? T : Expand<T>[]; | ||
export {}; |
@@ -1,1 +0,1 @@ | ||
import{onDocumentReady as d}from'./document-ready.js';let t=[];d(()=>{function e(n){n.target instanceof HTMLElement&&n.target!==document.body&&t[0]!==n.target&&(t.unshift(n.target),t=t.filter(r=>r!=null&&r.isConnected),t.splice(10))}window.addEventListener("click",e,{capture:!0}),window.addEventListener("mousedown",e,{capture:!0}),window.addEventListener("focus",e,{capture:!0}),document.body.addEventListener("click",e,{capture:!0}),document.body.addEventListener("mousedown",e,{capture:!0}),document.body.addEventListener("focus",e,{capture:!0})});export{t as history}; | ||
import{onDocumentReady as d}from'./document-ready.js';import{focusableSelector as u}from'./focus-management.js';let r=[];d(()=>{function e(t){if(!(t.target instanceof HTMLElement)||t.target===document.body||r[0]===t.target)return;let n=t.target;n=n.closest(u),r.unshift(n!=null?n:t.target),r=r.filter(o=>o!=null&&o.isConnected),r.splice(10)}window.addEventListener("click",e,{capture:!0}),window.addEventListener("mousedown",e,{capture:!0}),window.addEventListener("focus",e,{capture:!0}),document.body.addEventListener("click",e,{capture:!0}),document.body.addEventListener("mousedown",e,{capture:!0}),document.body.addEventListener("focus",e,{capture:!0})});export{r as history}; |
import type { MutableRefObject } from 'react'; | ||
export declare let focusableSelector: string; | ||
export declare enum Focus { | ||
@@ -3,0 +4,0 @@ /** Focus the first non-disabled element */ |
@@ -1,1 +0,1 @@ | ||
import{disposables as N}from'./disposables.js';import{match as L}from'./match.js';import{getOwnerDocument as E}from'./owner.js';let f=["[contentEditable=true]","[tabindex]","a[href]","area[href]","button:not([disabled])","iframe","input:not([disabled])","select:not([disabled])","textarea:not([disabled])"].map(e=>`${e}:not([tabindex='-1'])`).join(","),p=["[data-autofocus]"].map(e=>`${e}:not([tabindex='-1'])`).join(",");var F=(n=>(n[n.First=1]="First",n[n.Previous=2]="Previous",n[n.Next=4]="Next",n[n.Last=8]="Last",n[n.WrapAround=16]="WrapAround",n[n.NoScroll=32]="NoScroll",n[n.AutoFocus=64]="AutoFocus",n))(F||{}),T=(o=>(o[o.Error=0]="Error",o[o.Overflow=1]="Overflow",o[o.Success=2]="Success",o[o.Underflow=3]="Underflow",o))(T||{}),y=(t=>(t[t.Previous=-1]="Previous",t[t.Next=1]="Next",t))(y||{});function b(e=document.body){return e==null?[]:Array.from(e.querySelectorAll(f)).sort((r,t)=>Math.sign((r.tabIndex||Number.MAX_SAFE_INTEGER)-(t.tabIndex||Number.MAX_SAFE_INTEGER)))}function S(e=document.body){return e==null?[]:Array.from(e.querySelectorAll(p)).sort((r,t)=>Math.sign((r.tabIndex||Number.MAX_SAFE_INTEGER)-(t.tabIndex||Number.MAX_SAFE_INTEGER)))}var h=(t=>(t[t.Strict=0]="Strict",t[t.Loose=1]="Loose",t))(h||{});function A(e,r=0){var t;return e===((t=E(e))==null?void 0:t.body)?!1:L(r,{[0](){return e.matches(f)},[1](){let u=e;for(;u!==null;){if(u.matches(f))return!0;u=u.parentElement}return!1}})}function G(e){let r=E(e);N().nextFrame(()=>{r&&!A(r.activeElement,0)&&I(e)})}var H=(t=>(t[t.Keyboard=0]="Keyboard",t[t.Mouse=1]="Mouse",t))(H||{});typeof window!="undefined"&&typeof document!="undefined"&&(document.addEventListener("keydown",e=>{e.metaKey||e.altKey||e.ctrlKey||(document.documentElement.dataset.headlessuiFocusVisible="")},!0),document.addEventListener("click",e=>{e.detail===1?delete document.documentElement.dataset.headlessuiFocusVisible:e.detail===0&&(document.documentElement.dataset.headlessuiFocusVisible="")},!0));function I(e){e==null||e.focus({preventScroll:!0})}let w=["textarea","input"].join(",");function O(e){var r,t;return(t=(r=e==null?void 0:e.matches)==null?void 0:r.call(e,w))!=null?t:!1}function _(e,r=t=>t){return e.slice().sort((t,u)=>{let o=r(t),c=r(u);if(o===null||c===null)return 0;let l=o.compareDocumentPosition(c);return l&Node.DOCUMENT_POSITION_FOLLOWING?-1:l&Node.DOCUMENT_POSITION_PRECEDING?1:0})}function j(e,r){return P(b(),r,{relativeTo:e})}function P(e,r,{sorted:t=!0,relativeTo:u=null,skipElements:o=[]}={}){let c=Array.isArray(e)?e.length>0?e[0].ownerDocument:document:e.ownerDocument,l=Array.isArray(e)?t?_(e):e:r&64?S(e):b(e);o.length>0&&l.length>1&&(l=l.filter(s=>!o.some(a=>a!=null&&"current"in a?(a==null?void 0:a.current)===s:a===s))),u=u!=null?u:c.activeElement;let n=(()=>{if(r&5)return 1;if(r&10)return-1;throw new Error("Missing Focus.First, Focus.Previous, Focus.Next or Focus.Last")})(),x=(()=>{if(r&1)return 0;if(r&2)return Math.max(0,l.indexOf(u))-1;if(r&4)return Math.max(0,l.indexOf(u))+1;if(r&8)return l.length-1;throw new Error("Missing Focus.First, Focus.Previous, Focus.Next or Focus.Last")})(),M=r&32?{preventScroll:!0}:{},m=0,d=l.length,i;do{if(m>=d||m+d<=0)return 0;let s=x+m;if(r&16)s=(s+d)%d;else{if(s<0)return 3;if(s>=d)return 1}i=l[s],i==null||i.focus(M),m+=n}while(i!==c.activeElement);return r&6&&O(i)&&i.select(),2}export{F as Focus,T as FocusResult,h as FocusableMode,I as focusElement,j as focusFrom,P as focusIn,S as getAutoFocusableElements,b as getFocusableElements,A as isFocusableElement,G as restoreFocusIfNecessary,_ as sortByDomNode}; | ||
import{disposables as N}from'./disposables.js';import{match as L}from'./match.js';import{getOwnerDocument as E}from'./owner.js';let f=["[contentEditable=true]","[tabindex]","a[href]","area[href]","button:not([disabled])","iframe","input:not([disabled])","select:not([disabled])","textarea:not([disabled])"].map(e=>`${e}:not([tabindex='-1'])`).join(","),p=["[data-autofocus]"].map(e=>`${e}:not([tabindex='-1'])`).join(",");var F=(n=>(n[n.First=1]="First",n[n.Previous=2]="Previous",n[n.Next=4]="Next",n[n.Last=8]="Last",n[n.WrapAround=16]="WrapAround",n[n.NoScroll=32]="NoScroll",n[n.AutoFocus=64]="AutoFocus",n))(F||{}),T=(o=>(o[o.Error=0]="Error",o[o.Overflow=1]="Overflow",o[o.Success=2]="Success",o[o.Underflow=3]="Underflow",o))(T||{}),y=(t=>(t[t.Previous=-1]="Previous",t[t.Next=1]="Next",t))(y||{});function b(e=document.body){return e==null?[]:Array.from(e.querySelectorAll(f)).sort((r,t)=>Math.sign((r.tabIndex||Number.MAX_SAFE_INTEGER)-(t.tabIndex||Number.MAX_SAFE_INTEGER)))}function S(e=document.body){return e==null?[]:Array.from(e.querySelectorAll(p)).sort((r,t)=>Math.sign((r.tabIndex||Number.MAX_SAFE_INTEGER)-(t.tabIndex||Number.MAX_SAFE_INTEGER)))}var h=(t=>(t[t.Strict=0]="Strict",t[t.Loose=1]="Loose",t))(h||{});function A(e,r=0){var t;return e===((t=E(e))==null?void 0:t.body)?!1:L(r,{[0](){return e.matches(f)},[1](){let u=e;for(;u!==null;){if(u.matches(f))return!0;u=u.parentElement}return!1}})}function G(e){let r=E(e);N().nextFrame(()=>{r&&!A(r.activeElement,0)&&I(e)})}var H=(t=>(t[t.Keyboard=0]="Keyboard",t[t.Mouse=1]="Mouse",t))(H||{});typeof window!="undefined"&&typeof document!="undefined"&&(document.addEventListener("keydown",e=>{e.metaKey||e.altKey||e.ctrlKey||(document.documentElement.dataset.headlessuiFocusVisible="")},!0),document.addEventListener("click",e=>{e.detail===1?delete document.documentElement.dataset.headlessuiFocusVisible:e.detail===0&&(document.documentElement.dataset.headlessuiFocusVisible="")},!0));function I(e){e==null||e.focus({preventScroll:!0})}let w=["textarea","input"].join(",");function O(e){var r,t;return(t=(r=e==null?void 0:e.matches)==null?void 0:r.call(e,w))!=null?t:!1}function _(e,r=t=>t){return e.slice().sort((t,u)=>{let o=r(t),c=r(u);if(o===null||c===null)return 0;let l=o.compareDocumentPosition(c);return l&Node.DOCUMENT_POSITION_FOLLOWING?-1:l&Node.DOCUMENT_POSITION_PRECEDING?1:0})}function j(e,r){return P(b(),r,{relativeTo:e})}function P(e,r,{sorted:t=!0,relativeTo:u=null,skipElements:o=[]}={}){let c=Array.isArray(e)?e.length>0?e[0].ownerDocument:document:e.ownerDocument,l=Array.isArray(e)?t?_(e):e:r&64?S(e):b(e);o.length>0&&l.length>1&&(l=l.filter(s=>!o.some(a=>a!=null&&"current"in a?(a==null?void 0:a.current)===s:a===s))),u=u!=null?u:c.activeElement;let n=(()=>{if(r&5)return 1;if(r&10)return-1;throw new Error("Missing Focus.First, Focus.Previous, Focus.Next or Focus.Last")})(),x=(()=>{if(r&1)return 0;if(r&2)return Math.max(0,l.indexOf(u))-1;if(r&4)return Math.max(0,l.indexOf(u))+1;if(r&8)return l.length-1;throw new Error("Missing Focus.First, Focus.Previous, Focus.Next or Focus.Last")})(),M=r&32?{preventScroll:!0}:{},m=0,d=l.length,i;do{if(m>=d||m+d<=0)return 0;let s=x+m;if(r&16)s=(s+d)%d;else{if(s<0)return 3;if(s>=d)return 1}i=l[s],i==null||i.focus(M),m+=n}while(i!==c.activeElement);return r&6&&O(i)&&i.select(),2}export{F as Focus,T as FocusResult,h as FocusableMode,I as focusElement,j as focusFrom,P as focusIn,f as focusableSelector,S as getAutoFocusableElements,b as getFocusableElements,A as isFocusableElement,G as restoreFocusIfNecessary,_ as sortByDomNode}; |
import { type ElementType, type ReactElement, type Ref } from 'react'; | ||
import type { Expand, Props, XOR, __ } from '../types.js'; | ||
import type { Expand, Props } from '../types.js'; | ||
export declare enum RenderFeatures { | ||
@@ -24,10 +24,9 @@ /** No features at all */ | ||
} | ||
type PropsForFeature<TPassedInFeatures extends RenderFeatures, TForFeature extends RenderFeatures, TProps> = { | ||
[P in TPassedInFeatures]: P extends TForFeature ? TProps : __; | ||
}[TPassedInFeatures]; | ||
export type PropsForFeatures<T extends RenderFeatures> = XOR<PropsForFeature<T, RenderFeatures.Static, { | ||
type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never; | ||
type PropsForFeature<TPassedInFeatures extends RenderFeatures, TForFeature extends RenderFeatures, TProps> = TPassedInFeatures extends TForFeature ? TProps : {}; | ||
export type PropsForFeatures<T extends RenderFeatures> = Expand<UnionToIntersection<PropsForFeature<T, RenderFeatures.Static, { | ||
static?: boolean; | ||
}>, PropsForFeature<T, RenderFeatures.RenderStrategy, { | ||
}> | PropsForFeature<T, RenderFeatures.RenderStrategy, { | ||
unmount?: boolean; | ||
}>>; | ||
}>>>; | ||
export declare function render<TFeature extends RenderFeatures, TTag extends ElementType, TSlot>({ ourProps, theirProps, slot, defaultTag, features, visible, name, mergeRefs, }: { | ||
@@ -34,0 +33,0 @@ ourProps: Expand<Props<TTag, TSlot, any> & PropsForFeatures<TFeature>> & { |
@@ -1,4 +0,4 @@ | ||
import{Fragment as R,cloneElement as x,createElement as E,forwardRef as j,isValidElement as S,useCallback as v,useRef as w}from"react";import{classNames as P}from'./class-names.js';import{match as k}from'./match.js';var O=(a=>(a[a.None=0]="None",a[a.RenderStrategy=1]="RenderStrategy",a[a.Static=2]="Static",a))(O||{}),M=(e=>(e[e.Unmount=0]="Unmount",e[e.Hidden=1]="Hidden",e))(M||{});function H({ourProps:r,theirProps:n,slot:e,defaultTag:a,features:s,visible:t=!0,name:l,mergeRefs:i}){i=i!=null?i:A;let o=N(n,r);if(t)return b(o,e,a,l,i);let y=s!=null?s:0;if(y&2){let{static:f=!1,...u}=o;if(f)return b(u,e,a,l,i)}if(y&1){let{unmount:f=!0,...u}=o;return k(f?0:1,{[0](){return null},[1](){return b({...u,hidden:!0,style:{display:"none"}},e,a,l,i)}})}return b(o,e,a,l,i)}function b(r,n={},e,a,s){let{as:t=e,children:l,refName:i="ref",...o}=h(r,["unmount","static"]),y=r.ref!==void 0?{[i]:r.ref}:{},f=typeof l=="function"?l(n):l;"className"in o&&o.className&&typeof o.className=="function"&&(o.className=o.className(n)),o["aria-labelledby"]&&o["aria-labelledby"]===o.id&&(o["aria-labelledby"]=void 0);let u={};if(n){let d=!1,p=[];for(let[c,T]of Object.entries(n))typeof T=="boolean"&&(d=!0),T===!0&&p.push(c.replace(/([A-Z])/g,g=>`-${g.toLowerCase()}`));if(d){u["data-headlessui-state"]=p.join(" ");for(let c of p)u[`data-${c}`]=""}}if(t===R&&(Object.keys(m(o)).length>0||Object.keys(m(u)).length>0))if(!S(f)||Array.isArray(f)&&f.length>1){if(Object.keys(m(o)).length>0)throw new Error(['Passing props on "Fragment"!',"",`The current component <${a} /> is rendering a "Fragment".`,"However we need to passthrough the following props:",Object.keys(m(o)).concat(Object.keys(m(u))).map(d=>` - ${d}`).join(` | ||
import{Fragment as R,cloneElement as P,createElement as E,forwardRef as j,isValidElement as v,useCallback as S,useRef as w}from"react";import{classNames as x}from'./class-names.js';import{match as k}from'./match.js';var M=(a=>(a[a.None=0]="None",a[a.RenderStrategy=1]="RenderStrategy",a[a.Static=2]="Static",a))(M||{}),O=(e=>(e[e.Unmount=0]="Unmount",e[e.Hidden=1]="Hidden",e))(O||{});function H({ourProps:r,theirProps:n,slot:e,defaultTag:a,features:s,visible:t=!0,name:l,mergeRefs:i}){i=i!=null?i:A;let o=N(n,r);if(t)return b(o,e,a,l,i);let y=s!=null?s:0;if(y&2){let{static:f=!1,...u}=o;if(f)return b(u,e,a,l,i)}if(y&1){let{unmount:f=!0,...u}=o;return k(f?0:1,{[0](){return null},[1](){return b({...u,hidden:!0,style:{display:"none"}},e,a,l,i)}})}return b(o,e,a,l,i)}function b(r,n={},e,a,s){let{as:t=e,children:l,refName:i="ref",...o}=h(r,["unmount","static"]),y=r.ref!==void 0?{[i]:r.ref}:{},f=typeof l=="function"?l(n):l;"className"in o&&o.className&&typeof o.className=="function"&&(o.className=o.className(n)),o["aria-labelledby"]&&o["aria-labelledby"]===o.id&&(o["aria-labelledby"]=void 0);let u={};if(n){let d=!1,p=[];for(let[c,T]of Object.entries(n))typeof T=="boolean"&&(d=!0),T===!0&&p.push(c.replace(/([A-Z])/g,g=>`-${g.toLowerCase()}`));if(d){u["data-headlessui-state"]=p.join(" ");for(let c of p)u[`data-${c}`]=""}}if(t===R&&(Object.keys(m(o)).length>0||Object.keys(m(u)).length>0))if(!v(f)||Array.isArray(f)&&f.length>1){if(Object.keys(m(o)).length>0)throw new Error(['Passing props on "Fragment"!',"",`The current component <${a} /> is rendering a "Fragment".`,"However we need to passthrough the following props:",Object.keys(m(o)).concat(Object.keys(m(u))).map(d=>` - ${d}`).join(` | ||
`),"","You can apply a few solutions:",['Add an `as="..."` prop, to ensure that we render an actual element instead of a "Fragment".',"Render a single element as the child so that we can forward the props onto that element."].map(d=>` - ${d}`).join(` | ||
`)].join(` | ||
`))}else{let d=f.props,p=d==null?void 0:d.className,c=typeof p=="function"?(...F)=>P(p(...F),o.className):P(p,o.className),T=c?{className:c}:{},g=N(f.props,m(h(o,["ref"])));for(let F in u)F in g&&delete u[F];return x(f,Object.assign({},g,u,y,{ref:s(f.ref,y.ref)},T))}return E(t,Object.assign({},h(o,["ref"]),t!==R&&y,t!==R&&u),f)}function U(){let r=w([]),n=v(e=>{for(let a of r.current)a!=null&&(typeof a=="function"?a(e):a.current=e)},[]);return(...e)=>{if(!e.every(a=>a==null))return r.current=e,n}}function A(...r){return r.every(n=>n==null)?void 0:n=>{for(let e of r)e!=null&&(typeof e=="function"?e(n):e.current=n)}}function N(...r){var a;if(r.length===0)return{};if(r.length===1)return r[0];let n={},e={};for(let s of r)for(let t in s)t.startsWith("on")&&typeof s[t]=="function"?((a=e[t])!=null||(e[t]=[]),e[t].push(s[t])):n[t]=s[t];if(n.disabled||n["aria-disabled"])for(let s in e)/^(on(?:Click|Pointer|Mouse|Key)(?:Down|Up|Press)?)$/.test(s)&&(e[s]=[t=>{var l;return(l=t==null?void 0:t.preventDefault)==null?void 0:l.call(t)}]);for(let s in e)Object.assign(n,{[s](t,...l){let i=e[s];for(let o of i){if((t instanceof Event||(t==null?void 0:t.nativeEvent)instanceof Event)&&t.defaultPrevented)return;o(t,...l)}}});return n}function D(...r){var a;if(r.length===0)return{};if(r.length===1)return r[0];let n={},e={};for(let s of r)for(let t in s)t.startsWith("on")&&typeof s[t]=="function"?((a=e[t])!=null||(e[t]=[]),e[t].push(s[t])):n[t]=s[t];for(let s in e)Object.assign(n,{[s](...t){let l=e[s];for(let i of l)i==null||i(...t)}});return n}function I(r){var n;return Object.assign(j(r),{displayName:(n=r.displayName)!=null?n:r.name})}function m(r){let n=Object.assign({},r);for(let e in n)n[e]===void 0&&delete n[e];return n}function h(r,n=[]){let e=Object.assign({},r);for(let a of n)a in e&&delete e[a];return e}export{O as RenderFeatures,M as RenderStrategy,m as compact,I as forwardRefWithAs,D as mergeProps,H as render,U as useMergeRefsFn}; | ||
`))}else{let d=f.props,p=d==null?void 0:d.className,c=typeof p=="function"?(...F)=>x(p(...F),o.className):x(p,o.className),T=c?{className:c}:{},g=N(f.props,m(h(o,["ref"])));for(let F in u)F in g&&delete u[F];return P(f,Object.assign({},g,u,y,{ref:s(f.ref,y.ref)},T))}return E(t,Object.assign({},h(o,["ref"]),t!==R&&y,t!==R&&u),f)}function I(){let r=w([]),n=S(e=>{for(let a of r.current)a!=null&&(typeof a=="function"?a(e):a.current=e)},[]);return(...e)=>{if(!e.every(a=>a==null))return r.current=e,n}}function A(...r){return r.every(n=>n==null)?void 0:n=>{for(let e of r)e!=null&&(typeof e=="function"?e(n):e.current=n)}}function N(...r){var a;if(r.length===0)return{};if(r.length===1)return r[0];let n={},e={};for(let s of r)for(let t in s)t.startsWith("on")&&typeof s[t]=="function"?((a=e[t])!=null||(e[t]=[]),e[t].push(s[t])):n[t]=s[t];if(n.disabled||n["aria-disabled"])for(let s in e)/^(on(?:Click|Pointer|Mouse|Key)(?:Down|Up|Press)?)$/.test(s)&&(e[s]=[t=>{var l;return(l=t==null?void 0:t.preventDefault)==null?void 0:l.call(t)}]);for(let s in e)Object.assign(n,{[s](t,...l){let i=e[s];for(let o of i){if((t instanceof Event||(t==null?void 0:t.nativeEvent)instanceof Event)&&t.defaultPrevented)return;o(t,...l)}}});return n}function D(...r){var a;if(r.length===0)return{};if(r.length===1)return r[0];let n={},e={};for(let s of r)for(let t in s)t.startsWith("on")&&typeof s[t]=="function"?((a=e[t])!=null||(e[t]=[]),e[t].push(s[t])):n[t]=s[t];for(let s in e)Object.assign(n,{[s](...t){let l=e[s];for(let i of l)i==null||i(...t)}});return n}function W(r){var n;return Object.assign(j(r),{displayName:(n=r.displayName)!=null?n:r.name})}function m(r){let n=Object.assign({},r);for(let e in n)n[e]===void 0&&delete n[e];return n}function h(r,n=[]){let e=Object.assign({},r);for(let a of n)a in e&&delete e[a];return e}export{M as RenderFeatures,O as RenderStrategy,m as compact,W as forwardRefWithAs,D as mergeProps,H as render,I as useMergeRefsFn}; |
@@ -1,1 +0,1 @@ | ||
import*as r from"react";const s=r.createContext(null);function a(){return{groups:new Map,get(n,t){var c;let e=this.groups.get(n);e||(e=new Map,this.groups.set(n,e));let l=(c=e.get(t))!=null?c:0;e.set(t,l+1);let o=Array.from(e.keys()).indexOf(t);function i(){let u=e.get(t);u>1?e.set(t,u-1):e.delete(t)}return[o,i]}}}function C({children:n}){let t=r.useRef(a());return r.createElement(s.Provider,{value:t},n)}function d(n){let t=r.useContext(s);if(!t)throw new Error("You must wrap your component in a <StableCollection>");let e=f(),[l,o]=t.current.get(n,e);return r.useEffect(()=>o,[]),l}function f(){var l,o,i;let n=(i=(o=(l=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED)==null?void 0:l.ReactCurrentOwner)==null?void 0:o.current)!=null?i:null;if(!n)return Symbol();let t=[],e=n;for(;e;)t.push(e.index),e=e.return;return"$."+t.join(".")}export{C as StableCollection,d as useStableCollectionIndex}; | ||
import*as l from"react";const s=l.createContext(null);function a(){return{groups:new Map,get(o,e){var i;let t=this.groups.get(o);t||(t=new Map,this.groups.set(o,t));let n=(i=t.get(e))!=null?i:0;t.set(e,n+1);let r=Array.from(t.keys()).indexOf(e);function u(){let c=t.get(e);c>1?t.set(e,c-1):t.delete(e)}return[r,u]}}}function f({children:o}){let e=l.useRef(a());return l.createElement(s.Provider,{value:e},o)}function C(o){let e=l.useContext(s);if(!e)throw new Error("You must wrap your component in a <StableCollection>");let t=l.useId(),[n,r]=e.current.get(o,t);return l.useEffect(()=>r,[]),n}export{f as StableCollection,C as useStableCollectionIndex}; |
{ | ||
"name": "@headlessui/react", | ||
"version": "0.0.0-insiders.b517a39", | ||
"version": "0.0.0-insiders.b670896", | ||
"description": "A set of completely unstyled, fully accessible UI components for React, designed to integrate beautifully with Tailwind CSS.", | ||
@@ -45,19 +45,20 @@ "main": "dist/index.cjs", | ||
"peerDependencies": { | ||
"react": "^16 || ^17 || ^18", | ||
"react-dom": "^16 || ^17 || ^18" | ||
"react": "^18", | ||
"react-dom": "^18" | ||
}, | ||
"devDependencies": { | ||
"@testing-library/react": "^13.0.0", | ||
"@types/react": "^18.2.14", | ||
"@types/react-dom": "^18.2.6", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"snapshot-diff": "^0.8.1" | ||
"@testing-library/react": "^15.0.7", | ||
"@types/react": "^18.3.3", | ||
"@types/react-dom": "^18.3.0", | ||
"jsdom-testing-mocks": "^1.13.1", | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1", | ||
"snapshot-diff": "^0.10.0" | ||
}, | ||
"dependencies": { | ||
"@floating-ui/react": "^0.26.2", | ||
"@tanstack/react-virtual": "3.0.0-beta.60", | ||
"@react-aria/focus": "^3.14.3", | ||
"@react-aria/interactions": "3.0.0-nightly.2584" | ||
"@floating-ui/react": "^0.26.16", | ||
"@react-aria/focus": "^3.17.1", | ||
"@react-aria/interactions": "^3.21.3", | ||
"@tanstack/react-virtual": "^3.8.1" | ||
} | ||
} |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
299
0
915371
7
16447
7
+ Added@tanstack/react-virtual@3.10.9(transitive)
+ Added@tanstack/virtual-core@3.10.9(transitive)
- Removed@react-aria/interactions@3.0.0-nightly.2584(transitive)
- Removed@tanstack/react-virtual@3.0.0-beta.60(transitive)
- Removed@tanstack/virtual-core@3.0.0-beta.60(transitive)
Updated@floating-ui/react@^0.26.16
Updated@react-aria/focus@^3.17.1