@headlessui/vue
Advanced tools
Comparing version 0.0.0-insiders.f2179f3 to 0.0.0-insiders.f26cca5
import { type PropType } from 'vue'; | ||
declare function defaultComparator<T>(a: T, z: T): boolean; | ||
export declare let Combobox: import("vue").DefineComponent<{ | ||
@@ -14,3 +13,4 @@ as: { | ||
type: (StringConstructor | FunctionConstructor)[]; | ||
default: () => typeof defaultComparator; | ||
nullable: boolean; | ||
default: null; | ||
}; | ||
@@ -45,2 +45,9 @@ modelValue: { | ||
}; | ||
virtual: { | ||
type: PropType<{ | ||
options: unknown[]; | ||
disabled?: ((value: unknown) => boolean) | undefined; | ||
} | null>; | ||
default: null; | ||
}; | ||
}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, { | ||
@@ -61,3 +68,4 @@ [key: string]: any; | ||
type: (StringConstructor | FunctionConstructor)[]; | ||
default: () => typeof defaultComparator; | ||
nullable: boolean; | ||
default: null; | ||
}; | ||
@@ -92,2 +100,9 @@ modelValue: { | ||
}; | ||
virtual: { | ||
type: PropType<{ | ||
options: unknown[]; | ||
disabled?: ((value: unknown) => boolean) | undefined; | ||
} | null>; | ||
default: null; | ||
}; | ||
}>> & { | ||
@@ -104,2 +119,6 @@ "onUpdate:modelValue"?: ((_value: any) => any) | undefined; | ||
immediate: boolean; | ||
virtual: { | ||
options: unknown[]; | ||
disabled?: ((value: unknown) => boolean) | undefined; | ||
} | null; | ||
}>; | ||
@@ -281,2 +300,6 @@ export declare let ComboboxLabel: import("vue").DefineComponent<{ | ||
}; | ||
order: { | ||
type: NumberConstructor[]; | ||
default: null; | ||
}; | ||
}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, { | ||
@@ -298,6 +321,10 @@ [key: string]: any; | ||
}; | ||
order: { | ||
type: NumberConstructor[]; | ||
default: null; | ||
}; | ||
}>>, { | ||
as: string | Record<string, any>; | ||
disabled: boolean; | ||
order: number; | ||
}>; | ||
export {}; |
@@ -1,1 +0,1 @@ | ||
import{computed as x,defineComponent as N,Fragment as ee,h as Q,inject as te,nextTick as H,onMounted as J,onUnmounted as oe,provide as ae,ref as A,toRaw as C,watch as W,watchEffect as G}from"vue";import{useControllable as ne}from'../../hooks/use-controllable.js';import{useId as U}from'../../hooks/use-id.js';import{useOutsideClick as le}from'../../hooks/use-outside-click.js';import{useResolveButtonType as ie}from'../../hooks/use-resolve-button-type.js';import{useTrackedPointer as ue}from'../../hooks/use-tracked-pointer.js';import{useTreeWalker as re}from'../../hooks/use-tree-walker.js';import{Features as se,Hidden as de}from'../../internal/hidden.js';import{State as q,useOpenClosed as fe,useOpenClosedProvider as pe}from'../../internal/open-closed.js';import{Keys as E}from'../../keyboard.js';import{history as X}from'../../utils/active-element-history.js';import{calculateActiveIndex as be,Focus as M}from'../../utils/calculate-active-index.js';import{disposables as Y}from'../../utils/disposables.js';import{dom as g}from'../../utils/dom.js';import{sortByDomNode as ve}from'../../utils/focus-management.js';import{objectToFormEntries as me}from'../../utils/form.js';import{match as j}from'../../utils/match.js';import{getOwnerDocument as ce}from'../../utils/owner.js';import{isMobile as xe}from'../../utils/platform.js';import{compact as ge,Features as _,omit as Z,render as K}from'../../utils/render.js';function Se(a,T){return a===T}var Ce=(p=>(p[p.Open=0]="Open",p[p.Closed=1]="Closed",p))(Ce||{}),Oe=(p=>(p[p.Single=0]="Single",p[p.Multi=1]="Multi",p))(Oe||{}),Re=(O=>(O[O.Pointer=0]="Pointer",O[O.Focus=1]="Focus",O[O.Other=2]="Other",O))(Re||{});let z=Symbol("ComboboxContext");function $(a){let T=te(z,null);if(T===null){let p=new Error(`<${a} /> is missing a parent <Combobox /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(p,$),p}return T}let Ue=N({name:"Combobox",emits:{"update:modelValue":a=>!0},props:{as:{type:[Object,String],default:"template"},disabled:{type:[Boolean],default:!1},by:{type:[String,Function],default:()=>Se},modelValue:{type:[Object,String,Number,Boolean],default:void 0},defaultValue:{type:[Object,String,Number,Boolean],default:void 0},form:{type:String,optional:!0},name:{type:String,optional:!0},nullable:{type:Boolean,default:!1},multiple:{type:[Boolean],default:!1},immediate:{type:[Boolean],default:!1}},inheritAttrs:!1,setup(a,{slots:T,attrs:p,emit:O}){let t=A(1),e=A(null),y=A(null),f=A(null),r=A(null),b=A({static:!1,hold:!1}),v=A([]),R=A(null),h=A(2),V=A(!1);function L(n=u=>u){let u=R.value!==null?v.value[R.value]:null,s=ve(n(v.value.slice()),d=>g(d.dataRef.domRef)),i=u?s.indexOf(u):null;return i===-1&&(i=null),{options:s,activeOptionIndex:i}}let k=x(()=>a.multiple?1:0),S=x(()=>a.nullable),[F,o]=ne(x(()=>a.modelValue),n=>O("update:modelValue",n),x(()=>a.defaultValue)),m=x(()=>F.value===void 0?j(k.value,{[1]:[],[0]:void 0}):F.value),c=null,I=null,l={comboboxState:t,value:m,mode:k,compare(n,u){if(typeof a.by=="string"){let s=a.by;return(n==null?void 0:n[s])===(u==null?void 0:u[s])}return a.by(n,u)},defaultValue:x(()=>a.defaultValue),nullable:S,immediate:x(()=>a.immediate),inputRef:y,labelRef:e,buttonRef:f,optionsRef:r,disabled:x(()=>a.disabled),options:v,change(n){o(n)},activeOptionIndex:x(()=>{if(V.value&&R.value===null&&v.value.length>0){let n=v.value.findIndex(u=>!u.dataRef.disabled);n!==-1&&(R.value=n)}return R.value}),activationTrigger:h,optionsPropsRef:b,closeCombobox(){V.value=!1,!a.disabled&&t.value!==1&&(t.value=1,R.value=null)},openCombobox(){if(V.value=!0,a.disabled||t.value===0)return;let n=v.value.findIndex(u=>{let s=C(u.dataRef.value);return j(k.value,{[0]:()=>l.compare(C(l.value.value),C(s)),[1]:()=>C(l.value.value).some(d=>l.compare(C(d),C(s)))})});n!==-1&&(R.value=n),t.value=0},setActivationTrigger(n){h.value=n},goToOption(n,u,s){V.value=!1,c!==null&&cancelAnimationFrame(c),c=requestAnimationFrame(()=>{if(a.disabled||r.value&&!b.value.static&&t.value===1)return;let i=L();if(i.activeOptionIndex===null){let P=i.options.findIndex(B=>!B.dataRef.disabled);P!==-1&&(i.activeOptionIndex=P)}let d=be(n===M.Specific?{focus:M.Specific,id:u}:{focus:n},{resolveItems:()=>i.options,resolveActiveIndex:()=>i.activeOptionIndex,resolveId:P=>P.id,resolveDisabled:P=>P.dataRef.disabled});R.value=d,h.value=s!=null?s:2,v.value=i.options})},selectOption(n){let u=v.value.find(i=>i.id===n);if(!u)return;let{dataRef:s}=u;o(j(k.value,{[0]:()=>s.value,[1]:()=>{let i=C(l.value.value).slice(),d=C(s.value),P=i.findIndex(B=>l.compare(d,C(B)));return P===-1?i.push(d):i.splice(P,1),i}}))},selectActiveOption(){if(l.activeOptionIndex.value===null)return;let{dataRef:n,id:u}=v.value[l.activeOptionIndex.value];o(j(k.value,{[0]:()=>n.value,[1]:()=>{let s=C(l.value.value).slice(),i=C(n.value),d=s.findIndex(P=>l.compare(i,C(P)));return d===-1?s.push(i):s.splice(d,1),s}})),l.goToOption(M.Specific,u)},registerOption(n,u){I&&cancelAnimationFrame(I);let s={id:n,dataRef:u},i=L(d=>(d.push(s),d));if(R.value===null){let d=u.value.value;j(k.value,{[0]:()=>l.compare(C(l.value.value),C(d)),[1]:()=>C(l.value.value).some(B=>l.compare(C(B),C(d)))})&&(i.activeOptionIndex=i.options.indexOf(s))}v.value=i.options,R.value=i.activeOptionIndex,h.value=2,i.options.some(d=>!g(d.dataRef.domRef))&&(I=requestAnimationFrame(()=>{let d=L();v.value=d.options,R.value=d.activeOptionIndex}))},unregisterOption(n){var s;l.activeOptionIndex.value!==null&&((s=l.options.value[l.activeOptionIndex.value])==null?void 0:s.id)===n&&(V.value=!0);let u=L(i=>{let d=i.findIndex(P=>P.id===n);return d!==-1&&i.splice(d,1),i});v.value=u.options,R.value=u.activeOptionIndex,h.value=2}};le([y,f,r],()=>l.closeCombobox(),x(()=>t.value===0)),ae(z,l),pe(x(()=>j(t.value,{[0]:q.Open,[1]:q.Closed})));let w=x(()=>l.activeOptionIndex.value===null?null:v.value[l.activeOptionIndex.value].dataRef.value),D=x(()=>{var n;return(n=g(y))==null?void 0:n.closest("form")});return J(()=>{W([D],()=>{if(!D.value||a.defaultValue===void 0)return;function n(){l.change(a.defaultValue)}return D.value.addEventListener("reset",n),()=>{var u;(u=D.value)==null||u.removeEventListener("reset",n)}},{immediate:!0})}),()=>{let{name:n,disabled:u,form:s,...i}=a,d={open:t.value===0,disabled:u,activeIndex:l.activeOptionIndex.value,activeOption:w.value,value:m.value};return Q(ee,[...n!=null&&m.value!=null?me({[n]:m.value}).map(([P,B])=>Q(de,ge({features:se.Hidden,key:P,as:"input",type:"hidden",hidden:!0,readOnly:!0,form:s,name:P,value:B}))):[],K({theirProps:{...p,...Z(i,["modelValue","defaultValue","nullable","multiple","immediate","onUpdate:modelValue","by"])},ourProps:{},slot:d,slots:T,attrs:p,name:"Combobox"})])}}}),qe=N({name:"ComboboxLabel",props:{as:{type:[Object,String],default:"label"},id:{type:String,default:()=>`headlessui-combobox-label-${U()}`}},setup(a,{attrs:T,slots:p}){let O=$("ComboboxLabel");function t(){var e;(e=g(O.inputRef))==null||e.focus({preventScroll:!0})}return()=>{let e={open:O.comboboxState.value===0,disabled:O.disabled.value},{id:y,...f}=a,r={id:y,ref:O.labelRef,onClick:t};return K({ourProps:r,theirProps:f,slot:e,attrs:T,slots:p,name:"ComboboxLabel"})}}}),_e=N({name:"ComboboxButton",props:{as:{type:[Object,String],default:"button"},id:{type:String,default:()=>`headlessui-combobox-button-${U()}`}},setup(a,{attrs:T,slots:p,expose:O}){let t=$("ComboboxButton");O({el:t.buttonRef,$el:t.buttonRef});function e(r){t.disabled.value||(t.comboboxState.value===0?t.closeCombobox():(r.preventDefault(),t.openCombobox()),H(()=>{var b;return(b=g(t.inputRef))==null?void 0:b.focus({preventScroll:!0})}))}function y(r){switch(r.key){case E.ArrowDown:r.preventDefault(),r.stopPropagation(),t.comboboxState.value===1&&t.openCombobox(),H(()=>{var b;return(b=t.inputRef.value)==null?void 0:b.focus({preventScroll:!0})});return;case E.ArrowUp:r.preventDefault(),r.stopPropagation(),t.comboboxState.value===1&&(t.openCombobox(),H(()=>{t.value.value||t.goToOption(M.Last)})),H(()=>{var b;return(b=t.inputRef.value)==null?void 0:b.focus({preventScroll:!0})});return;case E.Escape:if(t.comboboxState.value!==0)return;r.preventDefault(),t.optionsRef.value&&!t.optionsPropsRef.value.static&&r.stopPropagation(),t.closeCombobox(),H(()=>{var b;return(b=t.inputRef.value)==null?void 0:b.focus({preventScroll:!0})});return}}let f=ie(x(()=>({as:a.as,type:T.type})),t.buttonRef);return()=>{var h,V;let r={open:t.comboboxState.value===0,disabled:t.disabled.value,value:t.value.value},{id:b,...v}=a,R={ref:t.buttonRef,id:b,type:f.value,tabindex:"-1","aria-haspopup":"listbox","aria-controls":(h=g(t.optionsRef))==null?void 0:h.id,"aria-expanded":t.comboboxState.value===0,"aria-labelledby":t.labelRef.value?[(V=g(t.labelRef))==null?void 0:V.id,b].join(" "):void 0,disabled:t.disabled.value===!0?!0:void 0,onKeydown:y,onClick:e};return K({ourProps:R,theirProps:v,slot:r,attrs:T,slots:p,name:"ComboboxButton"})}}}),Je=N({name:"ComboboxInput",props:{as:{type:[Object,String],default:"input"},static:{type:Boolean,default:!1},unmount:{type:Boolean,default:!0},displayValue:{type:Function},defaultValue:{type:String,default:void 0},id:{type:String,default:()=>`headlessui-combobox-input-${U()}`}},emits:{change:a=>!0},setup(a,{emit:T,attrs:p,slots:O,expose:t}){let e=$("ComboboxInput"),y=x(()=>ce(g(e.inputRef))),f={value:!1};t({el:e.inputRef,$el:e.inputRef});function r(){e.change(null);let o=g(e.optionsRef);o&&(o.scrollTop=0),e.goToOption(M.Nothing)}let b=x(()=>{var m;let o=e.value.value;return g(e.inputRef)?typeof a.displayValue!="undefined"&&o!==void 0?(m=a.displayValue(o))!=null?m:"":typeof o=="string"?o:"":""});J(()=>{W([b,e.comboboxState,y],([o,m],[c,I])=>{if(f.value)return;let l=g(e.inputRef);l&&((I===0&&m===1||o!==c)&&(l.value=o),requestAnimationFrame(()=>{var n;if(f.value||!l||((n=y.value)==null?void 0:n.activeElement)!==l)return;let{selectionStart:w,selectionEnd:D}=l;Math.abs((D!=null?D:0)-(w!=null?w:0))===0&&w===0&&l.setSelectionRange(l.value.length,l.value.length)}))},{immediate:!0}),W([e.comboboxState],([o],[m])=>{if(o===0&&m===1){if(f.value)return;let c=g(e.inputRef);if(!c)return;let I=c.value,{selectionStart:l,selectionEnd:w,selectionDirection:D}=c;c.value="",c.value=I,D!==null?c.setSelectionRange(l,w,D):c.setSelectionRange(l,w)}})});let v=A(!1);function R(){v.value=!0}function h(){Y().nextFrame(()=>{v.value=!1})}function V(o){switch(f.value=!0,o.key){case E.Enter:if(f.value=!1,e.comboboxState.value!==0||v.value)return;if(o.preventDefault(),o.stopPropagation(),e.activeOptionIndex.value===null){e.closeCombobox();return}e.selectActiveOption(),e.mode.value===0&&e.closeCombobox();break;case E.ArrowDown:return f.value=!1,o.preventDefault(),o.stopPropagation(),j(e.comboboxState.value,{[0]:()=>e.goToOption(M.Next),[1]:()=>e.openCombobox()});case E.ArrowUp:return f.value=!1,o.preventDefault(),o.stopPropagation(),j(e.comboboxState.value,{[0]:()=>e.goToOption(M.Previous),[1]:()=>{e.openCombobox(),H(()=>{e.value.value||e.goToOption(M.Last)})}});case E.Home:if(o.shiftKey)break;return f.value=!1,o.preventDefault(),o.stopPropagation(),e.goToOption(M.First);case E.PageUp:return f.value=!1,o.preventDefault(),o.stopPropagation(),e.goToOption(M.First);case E.End:if(o.shiftKey)break;return f.value=!1,o.preventDefault(),o.stopPropagation(),e.goToOption(M.Last);case E.PageDown:return f.value=!1,o.preventDefault(),o.stopPropagation(),e.goToOption(M.Last);case E.Escape:if(f.value=!1,e.comboboxState.value!==0)return;o.preventDefault(),e.optionsRef.value&&!e.optionsPropsRef.value.static&&o.stopPropagation(),e.nullable.value&&e.mode.value===0&&e.value.value===null&&r(),e.closeCombobox();break;case E.Tab:if(f.value=!1,e.comboboxState.value!==0)return;e.mode.value===0&&e.activationTrigger.value!==1&&e.selectActiveOption(),e.closeCombobox();break}}function L(o){T("change",o),e.nullable.value&&e.mode.value===0&&o.target.value===""&&r(),e.openCombobox()}function k(o){var c,I,l;let m=(c=o.relatedTarget)!=null?c:X.find(w=>w!==o.currentTarget);if(f.value=!1,!((I=g(e.optionsRef))!=null&&I.contains(m))&&!((l=g(e.buttonRef))!=null&&l.contains(m))&&e.comboboxState.value===0)return o.preventDefault(),e.mode.value===0&&(e.nullable.value&&e.value.value===null?r():e.activationTrigger.value!==1&&e.selectActiveOption()),e.closeCombobox()}function S(o){var c,I,l;let m=(c=o.relatedTarget)!=null?c:X.find(w=>w!==o.currentTarget);(I=g(e.buttonRef))!=null&&I.contains(m)||(l=g(e.optionsRef))!=null&&l.contains(m)||e.disabled.value||e.immediate.value&&e.comboboxState.value!==0&&(e.openCombobox(),Y().nextFrame(()=>{e.setActivationTrigger(1)}))}let F=x(()=>{var o,m,c,I;return(I=(c=(m=a.defaultValue)!=null?m:e.defaultValue.value!==void 0?(o=a.displayValue)==null?void 0:o.call(a,e.defaultValue.value):null)!=null?c:e.defaultValue.value)!=null?I:""});return()=>{var D,n,u,s,i,d;let o={open:e.comboboxState.value===0},{id:m,displayValue:c,onChange:I,...l}=a,w={"aria-controls":(D=e.optionsRef.value)==null?void 0:D.id,"aria-expanded":e.comboboxState.value===0,"aria-activedescendant":e.activeOptionIndex.value===null||(n=e.options.value[e.activeOptionIndex.value])==null?void 0:n.id,"aria-labelledby":(i=(u=g(e.labelRef))==null?void 0:u.id)!=null?i:(s=g(e.buttonRef))==null?void 0:s.id,"aria-autocomplete":"list",id:m,onCompositionstart:R,onCompositionend:h,onKeydown:V,onInput:L,onFocus:S,onBlur:k,role:"combobox",type:(d=p.type)!=null?d:"text",tabIndex:0,ref:e.inputRef,defaultValue:F.value,disabled:e.disabled.value===!0?!0:void 0};return K({ourProps:w,theirProps:l,slot:o,attrs:p,slots:O,features:_.RenderStrategy|_.Static,name:"ComboboxInput"})}}}),We=N({name:"ComboboxOptions",props:{as:{type:[Object,String],default:"ul"},static:{type:Boolean,default:!1},unmount:{type:Boolean,default:!0},hold:{type:[Boolean],default:!1}},setup(a,{attrs:T,slots:p,expose:O}){let t=$("ComboboxOptions"),e=`headlessui-combobox-options-${U()}`;O({el:t.optionsRef,$el:t.optionsRef}),G(()=>{t.optionsPropsRef.value.static=a.static}),G(()=>{t.optionsPropsRef.value.hold=a.hold});let y=fe(),f=x(()=>y!==null?(y.value&q.Open)===q.Open:t.comboboxState.value===0);return re({container:x(()=>g(t.optionsRef)),enabled:x(()=>t.comboboxState.value===0),accept(r){return r.getAttribute("role")==="option"?NodeFilter.FILTER_REJECT:r.hasAttribute("role")?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT},walk(r){r.setAttribute("role","none")}}),()=>{var R,h,V;let r={open:t.comboboxState.value===0},b={"aria-labelledby":(V=(R=g(t.labelRef))==null?void 0:R.id)!=null?V:(h=g(t.buttonRef))==null?void 0:h.id,id:e,ref:t.optionsRef,role:"listbox","aria-multiselectable":t.mode.value===1?!0:void 0},v=Z(a,["hold"]);return K({ourProps:b,theirProps:v,slot:r,attrs:T,slots:p,features:_.RenderStrategy|_.Static,visible:f.value,name:"ComboboxOptions"})}}}),Ge=N({name:"ComboboxOption",props:{as:{type:[Object,String],default:"li"},value:{type:[Object,String,Number,Boolean]},disabled:{type:Boolean,default:!1}},setup(a,{slots:T,attrs:p,expose:O}){let t=$("ComboboxOption"),e=`headlessui-combobox-option-${U()}`,y=A(null);O({el:y,$el:y});let f=x(()=>t.activeOptionIndex.value!==null?t.options.value[t.activeOptionIndex.value].id===e:!1),r=x(()=>j(t.mode.value,{[0]:()=>t.compare(C(t.value.value),C(a.value)),[1]:()=>C(t.value.value).some(S=>t.compare(C(S),C(a.value)))})),b=x(()=>({disabled:a.disabled,value:a.value,domRef:y}));J(()=>t.registerOption(e,b)),oe(()=>t.unregisterOption(e)),G(()=>{t.comboboxState.value===0&&f.value&&t.activationTrigger.value!==0&&H(()=>{var S,F;return(F=(S=g(y))==null?void 0:S.scrollIntoView)==null?void 0:F.call(S,{block:"nearest"})})});function v(S){if(a.disabled)return S.preventDefault();t.selectOption(e),xe()||requestAnimationFrame(()=>{var F;return(F=g(t.inputRef))==null?void 0:F.focus({preventScroll:!0})}),t.mode.value===0&&requestAnimationFrame(()=>t.closeCombobox())}function R(){if(a.disabled)return t.goToOption(M.Nothing);t.goToOption(M.Specific,e)}let h=ue();function V(S){h.update(S)}function L(S){h.wasMoved(S)&&(a.disabled||f.value||t.goToOption(M.Specific,e,0))}function k(S){h.wasMoved(S)&&(a.disabled||f.value&&(t.optionsPropsRef.value.hold||t.goToOption(M.Nothing)))}return()=>{let{disabled:S}=a,F={active:f.value,selected:r.value,disabled:S},o={id:e,ref:y,role:"option",tabIndex:S===!0?void 0:-1,"aria-disabled":S===!0?!0:void 0,"aria-selected":r.value,disabled:void 0,onClick:v,onFocus:R,onPointerenter:V,onMouseenter:V,onPointermove:L,onMousemove:L,onPointerleave:k,onMouseleave:k};return K({ourProps:o,theirProps:a,slot:F,attrs:p,slots:T,name:"ComboboxOption"})}}});export{Ue as Combobox,_e as ComboboxButton,Je as ComboboxInput,qe as ComboboxLabel,Ge as ComboboxOption,We as ComboboxOptions}; | ||
import{useVirtualizer as re}from"@tanstack/vue-virtual";import{Fragment as de,cloneVNode as se,computed as b,defineComponent as j,h as z,inject as ee,nextTick as H,onMounted as X,onUnmounted as fe,provide as te,reactive as ve,ref as A,toRaw as L,watch as q,watchEffect as Y}from"vue";import{useControllable as pe}from'../../hooks/use-controllable.js';import{useFrameDebounce as be}from'../../hooks/use-frame-debounce.js';import{useId as J}from'../../hooks/use-id.js';import{useOutsideClick as ce}from'../../hooks/use-outside-click.js';import{useResolveButtonType as me}from'../../hooks/use-resolve-button-type.js';import{useTrackedPointer as xe}from'../../hooks/use-tracked-pointer.js';import{useTreeWalker as ge}from'../../hooks/use-tree-walker.js';import{Hidden as Se,Features as Oe}from'../../internal/hidden.js';import{State as G,useOpenClosed as Ce,useOpenClosedProvider as Re}from'../../internal/open-closed.js';import{Keys as k}from'../../keyboard.js';import{MouseButton as ye}from'../../mouse.js';import{history as oe}from'../../utils/active-element-history.js';import{Focus as w,calculateActiveIndex as le}from'../../utils/calculate-active-index.js';import{disposables as ae}from'../../utils/disposables.js';import{dom as x}from'../../utils/dom.js';import{sortByDomNode as Te}from'../../utils/focus-management.js';import{objectToFormEntries as Ie}from'../../utils/form.js';import{match as $}from'../../utils/match.js';import{getOwnerDocument as he}from'../../utils/owner.js';import{isMobile as Pe}from'../../utils/platform.js';import{Features as Q,compact as we,omit as Z,render as _}from'../../utils/render.js';function De(a,I){return a===I}var Ee=(u=>(u[u.Open=0]="Open",u[u.Closed=1]="Closed",u))(Ee||{}),Ve=(u=>(u[u.Single=0]="Single",u[u.Multi=1]="Multi",u))(Ve||{}),Ae=(O=>(O[O.Pointer=0]="Pointer",O[O.Focus=1]="Focus",O[O.Other=2]="Other",O))(Ae||{});let ne=Symbol("ComboboxContext");function N(a){let I=ee(ne,null);if(I===null){let u=new Error(`<${a} /> is missing a parent <Combobox /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(u,N),u}return I}let ie=Symbol("VirtualContext"),Fe=j({name:"VirtualProvider",setup(a,{slots:I}){let u=N("VirtualProvider"),O=b(()=>{let r=x(u.optionsRef);if(!r)return{start:0,end:0};let f=window.getComputedStyle(r);return{start:parseFloat(f.paddingBlockStart||f.paddingTop),end:parseFloat(f.paddingBlockEnd||f.paddingBottom)}}),t=re(b(()=>({scrollPaddingStart:O.value.start,scrollPaddingEnd:O.value.end,count:u.virtual.value.options.length,estimateSize(){return 40},getScrollElement(){return x(u.optionsRef)},overscan:12}))),e=b(()=>{var r;return(r=u.virtual.value)==null?void 0:r.options}),C=A(0);return q([e],()=>{C.value+=1}),te(ie,u.virtual.value?t:null),()=>[z("div",{style:{position:"relative",width:"100%",height:`${t.value.getTotalSize()}px`},ref:r=>{if(r){if(typeof process!="undefined"&&process.env.JEST_WORKER_ID!==void 0||u.activationTrigger.value===0)return;u.activeOptionIndex.value!==null&&u.virtual.value.options.length>u.activeOptionIndex.value&&t.value.scrollToIndex(u.activeOptionIndex.value)}}},t.value.getVirtualItems().map(r=>se(I.default({option:u.virtual.value.options[r.index],open:u.comboboxState.value===0})[0],{key:`${C.value}-${r.index}`,"data-index":r.index,"aria-setsize":u.virtual.value.options.length,"aria-posinset":r.index+1,style:{position:"absolute",top:0,left:0,transform:`translateY(${r.start}px)`,overflowAnchor:"none"}})))]}}),lt=j({name:"Combobox",emits:{"update:modelValue":a=>!0},props:{as:{type:[Object,String],default:"template"},disabled:{type:[Boolean],default:!1},by:{type:[String,Function],nullable:!0,default:null},modelValue:{type:[Object,String,Number,Boolean],default:void 0},defaultValue:{type:[Object,String,Number,Boolean],default:void 0},form:{type:String,optional:!0},name:{type:String,optional:!0},nullable:{type:Boolean,default:!1},multiple:{type:[Boolean],default:!1},immediate:{type:[Boolean],default:!1},virtual:{type:Object,default:null}},inheritAttrs:!1,setup(a,{slots:I,attrs:u,emit:O}){let t=A(1),e=A(null),C=A(null),r=A(null),f=A(null),p=A({static:!1,hold:!1}),c=A([]),g=A(null),P=A(2),D=A(!1);function V(l=i=>i){let i=g.value!==null?c.value[g.value]:null,s=l(c.value.slice()),v=s.length>0&&s[0].dataRef.order.value!==null?s.sort((y,F)=>y.dataRef.order.value-F.dataRef.order.value):Te(s,y=>x(y.dataRef.domRef)),R=i?v.indexOf(i):null;return R===-1&&(R=null),{options:v,activeOptionIndex:R}}let M=b(()=>a.multiple?1:0),K=b(()=>a.nullable),[B,d]=pe(b(()=>a.modelValue),l=>O("update:modelValue",l),b(()=>a.defaultValue)),o=b(()=>B.value===void 0?$(M.value,{[1]:[],[0]:void 0}):B.value),m=null,S=null;function h(l){return $(M.value,{[0](){return d==null?void 0:d(l)},[1]:()=>{let i=L(n.value.value).slice(),s=L(l),v=i.findIndex(R=>n.compare(s,L(R)));return v===-1?i.push(s):i.splice(v,1),d==null?void 0:d(i)}})}let T=b(()=>{var l;return(l=a.virtual)==null?void 0:l.options});q([T],([l],[i])=>{if(n.virtual.value&&l&&i&&g.value!==null){let s=l.indexOf(i[g.value]);s!==-1?g.value=s:g.value=null}});let n={comboboxState:t,value:o,mode:M,compare(l,i){if(typeof a.by=="string"){let s=a.by;return(l==null?void 0:l[s])===(i==null?void 0:i[s])}return a.by===null?De(l,i):a.by(l,i)},calculateIndex(l){return n.virtual.value?a.by===null?n.virtual.value.options.indexOf(l):n.virtual.value.options.findIndex(i=>n.compare(i,l)):c.value.findIndex(i=>n.compare(i.dataRef.value,l))},defaultValue:b(()=>a.defaultValue),nullable:K,immediate:b(()=>a.immediate),virtual:b(()=>{var l;return a.virtual?{options:a.virtual.options,disabled:(l=a.virtual.disabled)!=null?l:()=>!1}:null}),inputRef:C,labelRef:e,buttonRef:r,optionsRef:f,disabled:b(()=>a.disabled),options:c,change(l){d(l)},activeOptionIndex:b(()=>{if(D.value&&g.value===null&&(n.virtual.value?n.virtual.value.options.length>0:c.value.length>0)){if(n.virtual.value){let i=n.virtual.value.options.findIndex(s=>{var v;return!((v=n.virtual.value)!=null&&v.disabled(s))});if(i!==-1)return i}let l=c.value.findIndex(i=>!i.dataRef.disabled);if(l!==-1)return l}return g.value}),activationTrigger:P,optionsPropsRef:p,closeCombobox(){D.value=!1,!a.disabled&&t.value!==1&&(t.value=1,g.value=null)},openCombobox(){if(D.value=!0,!a.disabled&&t.value!==0){if(n.value.value){let l=n.calculateIndex(n.value.value);l!==-1&&(g.value=l)}t.value=0}},setActivationTrigger(l){P.value=l},goToOption(l,i,s){D.value=!1,m!==null&&cancelAnimationFrame(m),m=requestAnimationFrame(()=>{if(a.disabled||f.value&&!p.value.static&&t.value===1)return;if(n.virtual.value){g.value=l===w.Specific?i:le({focus:l},{resolveItems:()=>n.virtual.value.options,resolveActiveIndex:()=>{var y,F;return(F=(y=n.activeOptionIndex.value)!=null?y:n.virtual.value.options.findIndex(W=>{var U;return!((U=n.virtual.value)!=null&&U.disabled(W))}))!=null?F:null},resolveDisabled:y=>n.virtual.value.disabled(y),resolveId(){throw new Error("Function not implemented.")}}),P.value=s!=null?s:2;return}let v=V();if(v.activeOptionIndex===null){let y=v.options.findIndex(F=>!F.dataRef.disabled);y!==-1&&(v.activeOptionIndex=y)}let R=l===w.Specific?i:le({focus:l},{resolveItems:()=>v.options,resolveActiveIndex:()=>v.activeOptionIndex,resolveId:y=>y.id,resolveDisabled:y=>y.dataRef.disabled});g.value=R,P.value=s!=null?s:2,c.value=v.options})},selectOption(l){let i=c.value.find(v=>v.id===l);if(!i)return;let{dataRef:s}=i;h(s.value)},selectActiveOption(){if(n.activeOptionIndex.value!==null){if(n.virtual.value)h(n.virtual.value.options[n.activeOptionIndex.value]);else{let{dataRef:l}=c.value[n.activeOptionIndex.value];h(l.value)}n.goToOption(w.Specific,n.activeOptionIndex.value)}},registerOption(l,i){let s=ve({id:l,dataRef:i});if(n.virtual.value){c.value.push(s);return}S&&cancelAnimationFrame(S);let v=V(R=>(R.push(s),R));g.value===null&&n.isSelected(i.value.value)&&(v.activeOptionIndex=v.options.indexOf(s)),c.value=v.options,g.value=v.activeOptionIndex,P.value=2,v.options.some(R=>!x(R.dataRef.domRef))&&(S=requestAnimationFrame(()=>{let R=V();c.value=R.options,g.value=R.activeOptionIndex}))},unregisterOption(l,i){if(m!==null&&cancelAnimationFrame(m),i&&(D.value=!0),n.virtual.value){c.value=c.value.filter(v=>v.id!==l);return}let s=V(v=>{let R=v.findIndex(y=>y.id===l);return R!==-1&&v.splice(R,1),v});c.value=s.options,g.value=s.activeOptionIndex,P.value=2},isSelected(l){return $(M.value,{[0]:()=>n.compare(L(n.value.value),L(l)),[1]:()=>L(n.value.value).some(i=>n.compare(L(i),L(l)))})},isActive(l){return g.value===n.calculateIndex(l)}};ce([C,r,f],()=>n.closeCombobox(),b(()=>t.value===0)),te(ne,n),Re(b(()=>$(t.value,{[0]:G.Open,[1]:G.Closed})));let E=b(()=>{var l;return(l=x(C))==null?void 0:l.closest("form")});return X(()=>{q([E],()=>{if(!E.value||a.defaultValue===void 0)return;function l(){n.change(a.defaultValue)}return E.value.addEventListener("reset",l),()=>{var i;(i=E.value)==null||i.removeEventListener("reset",l)}},{immediate:!0})}),()=>{var y,F,W;let{name:l,disabled:i,form:s,...v}=a,R={open:t.value===0,disabled:i,activeIndex:n.activeOptionIndex.value,activeOption:n.activeOptionIndex.value===null?null:n.virtual.value?n.virtual.value.options[(y=n.activeOptionIndex.value)!=null?y:0]:(W=(F=n.options.value[n.activeOptionIndex.value])==null?void 0:F.dataRef.value)!=null?W:null,value:o.value};return z(de,[...l!=null&&o.value!=null?Ie({[l]:o.value}).map(([U,ue])=>z(Se,we({features:Oe.Hidden,key:U,as:"input",type:"hidden",hidden:!0,readOnly:!0,form:s,disabled:i,name:U,value:ue}))):[],_({theirProps:{...u,...Z(v,["by","defaultValue","immediate","modelValue","multiple","nullable","onUpdate:modelValue","virtual"])},ourProps:{},slot:R,slots:I,attrs:u,name:"Combobox"})])}}}),at=j({name:"ComboboxLabel",props:{as:{type:[Object,String],default:"label"},id:{type:String,default:()=>`headlessui-combobox-label-${J()}`}},setup(a,{attrs:I,slots:u}){let O=N("ComboboxLabel");function t(){var e;(e=x(O.inputRef))==null||e.focus({preventScroll:!0})}return()=>{let e={open:O.comboboxState.value===0,disabled:O.disabled.value},{id:C,...r}=a,f={id:C,ref:O.labelRef,onClick:t};return _({ourProps:f,theirProps:r,slot:e,attrs:I,slots:u,name:"ComboboxLabel"})}}}),nt=j({name:"ComboboxButton",props:{as:{type:[Object,String],default:"button"},id:{type:String,default:()=>`headlessui-combobox-button-${J()}`}},setup(a,{attrs:I,slots:u,expose:O}){let t=N("ComboboxButton");O({el:t.buttonRef,$el:t.buttonRef});function e(f){t.disabled.value||(t.comboboxState.value===0?t.closeCombobox():(f.preventDefault(),t.openCombobox()),H(()=>{var p;return(p=x(t.inputRef))==null?void 0:p.focus({preventScroll:!0})}))}function C(f){switch(f.key){case k.ArrowDown:f.preventDefault(),f.stopPropagation(),t.comboboxState.value===1&&t.openCombobox(),H(()=>{var p;return(p=t.inputRef.value)==null?void 0:p.focus({preventScroll:!0})});return;case k.ArrowUp:f.preventDefault(),f.stopPropagation(),t.comboboxState.value===1&&(t.openCombobox(),H(()=>{t.value.value||t.goToOption(w.Last)})),H(()=>{var p;return(p=t.inputRef.value)==null?void 0:p.focus({preventScroll:!0})});return;case k.Escape:if(t.comboboxState.value!==0)return;f.preventDefault(),t.optionsRef.value&&!t.optionsPropsRef.value.static&&f.stopPropagation(),t.closeCombobox(),H(()=>{var p;return(p=t.inputRef.value)==null?void 0:p.focus({preventScroll:!0})});return}}let r=me(b(()=>({as:a.as,type:I.type})),t.buttonRef);return()=>{var P,D;let f={open:t.comboboxState.value===0,disabled:t.disabled.value,value:t.value.value},{id:p,...c}=a,g={ref:t.buttonRef,id:p,type:r.value,tabindex:"-1","aria-haspopup":"listbox","aria-controls":(P=x(t.optionsRef))==null?void 0:P.id,"aria-expanded":t.comboboxState.value===0,"aria-labelledby":t.labelRef.value?[(D=x(t.labelRef))==null?void 0:D.id,p].join(" "):void 0,disabled:t.disabled.value===!0?!0:void 0,onKeydown:C,onClick:e};return _({ourProps:g,theirProps:c,slot:f,attrs:I,slots:u,name:"ComboboxButton"})}}}),it=j({name:"ComboboxInput",props:{as:{type:[Object,String],default:"input"},static:{type:Boolean,default:!1},unmount:{type:Boolean,default:!0},displayValue:{type:Function},defaultValue:{type:String,default:void 0},id:{type:String,default:()=>`headlessui-combobox-input-${J()}`}},emits:{change:a=>!0},setup(a,{emit:I,attrs:u,slots:O,expose:t}){let e=N("ComboboxInput"),C=b(()=>he(x(e.inputRef))),r={value:!1};t({el:e.inputRef,$el:e.inputRef});function f(){e.change(null);let o=x(e.optionsRef);o&&(o.scrollTop=0),e.goToOption(w.Nothing)}let p=b(()=>{var m;let o=e.value.value;return x(e.inputRef)?typeof a.displayValue!="undefined"&&o!==void 0?(m=a.displayValue(o))!=null?m:"":typeof o=="string"?o:"":""});X(()=>{q([p,e.comboboxState,C],([o,m],[S,h])=>{if(r.value)return;let T=x(e.inputRef);T&&((h===0&&m===1||o!==S)&&(T.value=o),requestAnimationFrame(()=>{var l;if(r.value||!T||((l=C.value)==null?void 0:l.activeElement)!==T)return;let{selectionStart:n,selectionEnd:E}=T;Math.abs((E!=null?E:0)-(n!=null?n:0))===0&&n===0&&T.setSelectionRange(T.value.length,T.value.length)}))},{immediate:!0}),q([e.comboboxState],([o],[m])=>{if(o===0&&m===1){if(r.value)return;let S=x(e.inputRef);if(!S)return;let h=S.value,{selectionStart:T,selectionEnd:n,selectionDirection:E}=S;S.value="",S.value=h,E!==null?S.setSelectionRange(T,n,E):S.setSelectionRange(T,n)}})});let c=A(!1);function g(){c.value=!0}function P(){ae().nextFrame(()=>{c.value=!1})}let D=be();function V(o){switch(r.value=!0,D(()=>{c.value||(r.value=!1)}),o.key){case k.Enter:if(r.value=!1,e.comboboxState.value!==0||c.value)return;if(o.preventDefault(),o.stopPropagation(),e.activeOptionIndex.value===null){e.closeCombobox();return}e.selectActiveOption(),e.mode.value===0&&e.closeCombobox();break;case k.ArrowDown:return r.value=!1,o.preventDefault(),o.stopPropagation(),$(e.comboboxState.value,{[0]:()=>e.goToOption(w.Next),[1]:()=>e.openCombobox()});case k.ArrowUp:return r.value=!1,o.preventDefault(),o.stopPropagation(),$(e.comboboxState.value,{[0]:()=>e.goToOption(w.Previous),[1]:()=>{e.openCombobox(),H(()=>{e.value.value||e.goToOption(w.Last)})}});case k.Home:if(o.shiftKey)break;return r.value=!1,o.preventDefault(),o.stopPropagation(),e.goToOption(w.First);case k.PageUp:return r.value=!1,o.preventDefault(),o.stopPropagation(),e.goToOption(w.First);case k.End:if(o.shiftKey)break;return r.value=!1,o.preventDefault(),o.stopPropagation(),e.goToOption(w.Last);case k.PageDown:return r.value=!1,o.preventDefault(),o.stopPropagation(),e.goToOption(w.Last);case k.Escape:if(r.value=!1,e.comboboxState.value!==0)return;o.preventDefault(),e.optionsRef.value&&!e.optionsPropsRef.value.static&&o.stopPropagation(),e.nullable.value&&e.mode.value===0&&e.value.value===null&&f(),e.closeCombobox();break;case k.Tab:if(r.value=!1,e.comboboxState.value!==0)return;e.mode.value===0&&e.activationTrigger.value!==1&&e.selectActiveOption(),e.closeCombobox();break}}function M(o){I("change",o),e.nullable.value&&e.mode.value===0&&o.target.value===""&&f(),e.openCombobox()}function K(o){var S,h,T;let m=(S=o.relatedTarget)!=null?S:oe.find(n=>n!==o.currentTarget);if(r.value=!1,!((h=x(e.optionsRef))!=null&&h.contains(m))&&!((T=x(e.buttonRef))!=null&&T.contains(m))&&e.comboboxState.value===0)return o.preventDefault(),e.mode.value===0&&(e.nullable.value&&e.value.value===null?f():e.activationTrigger.value!==1&&e.selectActiveOption()),e.closeCombobox()}function B(o){var S,h,T;let m=(S=o.relatedTarget)!=null?S:oe.find(n=>n!==o.currentTarget);(h=x(e.buttonRef))!=null&&h.contains(m)||(T=x(e.optionsRef))!=null&&T.contains(m)||e.disabled.value||e.immediate.value&&e.comboboxState.value!==0&&(e.openCombobox(),ae().nextFrame(()=>{e.setActivationTrigger(1)}))}let d=b(()=>{var o,m,S,h;return(h=(S=(m=a.defaultValue)!=null?m:e.defaultValue.value!==void 0?(o=a.displayValue)==null?void 0:o.call(a,e.defaultValue.value):null)!=null?S:e.defaultValue.value)!=null?h:""});return()=>{var E,l,i,s,v,R,y;let o={open:e.comboboxState.value===0},{id:m,displayValue:S,onChange:h,...T}=a,n={"aria-controls":(E=e.optionsRef.value)==null?void 0:E.id,"aria-expanded":e.comboboxState.value===0,"aria-activedescendant":e.activeOptionIndex.value===null?void 0:e.virtual.value?(l=e.options.value.find(F=>!e.virtual.value.disabled(F.dataRef.value)&&e.compare(F.dataRef.value,e.virtual.value.options[e.activeOptionIndex.value])))==null?void 0:l.id:(i=e.options.value[e.activeOptionIndex.value])==null?void 0:i.id,"aria-labelledby":(R=(s=x(e.labelRef))==null?void 0:s.id)!=null?R:(v=x(e.buttonRef))==null?void 0:v.id,"aria-autocomplete":"list",id:m,onCompositionstart:g,onCompositionend:P,onKeydown:V,onInput:M,onFocus:B,onBlur:K,role:"combobox",type:(y=u.type)!=null?y:"text",tabIndex:0,ref:e.inputRef,defaultValue:d.value,disabled:e.disabled.value===!0?!0:void 0};return _({ourProps:n,theirProps:T,slot:o,attrs:u,slots:O,features:Q.RenderStrategy|Q.Static,name:"ComboboxInput"})}}}),ut=j({name:"ComboboxOptions",props:{as:{type:[Object,String],default:"ul"},static:{type:Boolean,default:!1},unmount:{type:Boolean,default:!0},hold:{type:[Boolean],default:!1}},setup(a,{attrs:I,slots:u,expose:O}){let t=N("ComboboxOptions"),e=`headlessui-combobox-options-${J()}`;O({el:t.optionsRef,$el:t.optionsRef}),Y(()=>{t.optionsPropsRef.value.static=a.static}),Y(()=>{t.optionsPropsRef.value.hold=a.hold});let C=Ce(),r=b(()=>C!==null?(C.value&G.Open)===G.Open:t.comboboxState.value===0);ge({container:b(()=>x(t.optionsRef)),enabled:b(()=>t.comboboxState.value===0),accept(p){return p.getAttribute("role")==="option"?NodeFilter.FILTER_REJECT:p.hasAttribute("role")?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT},walk(p){p.setAttribute("role","none")}});function f(p){p.preventDefault()}return()=>{var P,D,V;let p={open:t.comboboxState.value===0},c={"aria-labelledby":(V=(P=x(t.labelRef))==null?void 0:P.id)!=null?V:(D=x(t.buttonRef))==null?void 0:D.id,id:e,ref:t.optionsRef,role:"listbox","aria-multiselectable":t.mode.value===1?!0:void 0,onMousedown:f},g=Z(a,["hold"]);return _({ourProps:c,theirProps:g,slot:p,attrs:I,slots:t.virtual.value&&t.comboboxState.value===0?{...u,default:()=>[z(Fe,{},u.default)]}:u,features:Q.RenderStrategy|Q.Static,visible:r.value,name:"ComboboxOptions"})}}}),rt=j({name:"ComboboxOption",props:{as:{type:[Object,String],default:"li"},value:{type:[Object,String,Number,Boolean]},disabled:{type:Boolean,default:!1},order:{type:[Number],default:null}},setup(a,{slots:I,attrs:u,expose:O}){let t=N("ComboboxOption"),e=`headlessui-combobox-option-${J()}`,C=A(null),r=b(()=>{var d;return a.disabled||((d=t.virtual.value)==null?void 0:d.disabled(a.value))});O({el:C,$el:C});let f=b(()=>{var d;return t.virtual.value?t.activeOptionIndex.value===t.calculateIndex(a.value):t.activeOptionIndex.value===null?!1:((d=t.options.value[t.activeOptionIndex.value])==null?void 0:d.id)===e}),p=b(()=>t.isSelected(a.value)),c=ee(ie,null),g=b(()=>({disabled:a.disabled,value:a.value,domRef:C,order:b(()=>a.order)}));X(()=>t.registerOption(e,g)),fe(()=>t.unregisterOption(e,f.value)),Y(()=>{let d=x(C);d&&(c==null||c.value.measureElement(d))}),Y(()=>{t.comboboxState.value===0&&f.value&&(t.virtual.value||t.activationTrigger.value!==0&&H(()=>{var d,o;return(o=(d=x(C))==null?void 0:d.scrollIntoView)==null?void 0:o.call(d,{block:"nearest"})}))});function P(d){d.preventDefault(),d.button===ye.Left&&(r.value||(t.selectOption(e),Pe()||requestAnimationFrame(()=>{var o;return(o=x(t.inputRef))==null?void 0:o.focus({preventScroll:!0})}),t.mode.value===0&&t.closeCombobox()))}function D(){var o;if(a.disabled||(o=t.virtual.value)!=null&&o.disabled(a.value))return t.goToOption(w.Nothing);let d=t.calculateIndex(a.value);t.goToOption(w.Specific,d)}let V=xe();function M(d){V.update(d)}function K(d){var m;if(!V.wasMoved(d)||a.disabled||(m=t.virtual.value)!=null&&m.disabled(a.value)||f.value)return;let o=t.calculateIndex(a.value);t.goToOption(w.Specific,o,0)}function B(d){var o;V.wasMoved(d)&&(a.disabled||(o=t.virtual.value)!=null&&o.disabled(a.value)||f.value&&(t.optionsPropsRef.value.hold||t.goToOption(w.Nothing)))}return()=>{let{disabled:d}=a,o={active:f.value,selected:p.value,disabled:d},m={id:e,ref:C,role:"option",tabIndex:d===!0?void 0:-1,"aria-disabled":d===!0?!0:void 0,"aria-selected":p.value,disabled:void 0,onMousedown:P,onFocus:D,onPointerenter:M,onMouseenter:M,onPointermove:K,onMousemove:K,onPointerleave:B,onMouseleave:B},S=Z(a,["order","value"]);return _({ourProps:m,theirProps:S,slot:o,attrs:u,slots:I,name:"ComboboxOption"})}}});export{lt as Combobox,nt as ComboboxButton,it as ComboboxInput,at as ComboboxLabel,rt as ComboboxOption,ut as ComboboxOptions}; |
@@ -1,1 +0,1 @@ | ||
import{computed as o,defineComponent as O,h as g,inject as _,nextTick as ie,onMounted as L,onUnmounted as ue,provide as se,ref as y,watchEffect as pe}from"vue";import{FocusTrap as P}from'../../components/focus-trap/focus-trap.js';import{useDocumentOverflowLockedEffect as de}from'../../hooks/document-overflow/use-document-overflow.js';import{useEventListener as fe}from'../../hooks/use-event-listener.js';import{useId as b}from'../../hooks/use-id.js';import{useInert as q}from'../../hooks/use-inert.js';import{useOutsideClick as ge}from'../../hooks/use-outside-click.js';import{useRootContainers as ce}from'../../hooks/use-root-containers.js';import{State as x,useOpenClosed as ve}from'../../internal/open-closed.js';import{ForcePortalRoot as $}from'../../internal/portal-force-root.js';import{StackMessage as W,useStackProvider as me}from'../../internal/stack-context.js';import{Keys as De}from'../../keyboard.js';import{dom as F}from'../../utils/dom.js';import{match as Y}from'../../utils/match.js';import{getOwnerDocument as ye}from'../../utils/owner.js';import{Features as z,render as C}from'../../utils/render.js';import{Description as Se,useDescriptions as he}from'../description/description.js';import{Portal as G,PortalGroup as Oe,useNestedPortals as Pe}from'../portal/portal.js';var be=(l=>(l[l.Open=0]="Open",l[l.Closed=1]="Closed",l))(be||{});let j=Symbol("DialogContext");function T(t){let n=_(j,null);if(n===null){let l=new Error(`<${t} /> is missing a parent <Dialog /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(l,T),l}return n}let I="DC8F892D-2EBD-447C-A4C8-A03058436FF4",_e=O({name:"Dialog",inheritAttrs:!1,props:{as:{type:[Object,String],default:"div"},static:{type:Boolean,default:!1},unmount:{type:Boolean,default:!0},open:{type:[Boolean,String],default:I},initialFocus:{type:Object,default:null},id:{type:String,default:()=>`headlessui-dialog-${b()}`},role:{type:String,default:"dialog"}},emits:{close:t=>!0},setup(t,{emit:n,attrs:l,slots:u,expose:i}){var U;let r=y(!1);L(()=>{r.value=!0});let s=!1,v=o(()=>t.role==="dialog"||t.role==="alertdialog"?t.role:(s||(s=!0,console.warn(`Invalid role [${v}] passed to <Dialog />. Only \`dialog\` and and \`alertdialog\` are supported. Using \`dialog\` instead.`)),"dialog")),m=y(0),S=ve(),R=o(()=>t.open===I&&S!==null?(S.value&x.Open)===x.Open:t.open),c=y(null),E=o(()=>ye(c));if(i({el:c,$el:c}),!(t.open!==I||S!==null))throw new Error("You forgot to provide an `open` prop to the `Dialog`.");if(typeof R.value!="boolean")throw new Error(`You provided an \`open\` prop to the \`Dialog\`, but the value is not a boolean. Received: ${R.value===I?void 0:t.open}`);let f=o(()=>r.value&&R.value?0:1),k=o(()=>f.value===0),w=o(()=>m.value>1),H=_(j,null)!==null,[V,J]=Pe(),{resolveContainers:A,mainTreeNodeRef:N,MainTreeNode:Q}=ce({portals:V,defaultContainers:[o(()=>{var e;return(e=h.panelRef.value)!=null?e:c.value})]}),X=o(()=>w.value?"parent":"leaf"),K=o(()=>S!==null?(S.value&x.Closing)===x.Closing:!1),Z=o(()=>H||K.value?!1:k.value),ee=o(()=>{var e,a,p;return(p=Array.from((a=(e=E.value)==null?void 0:e.querySelectorAll("body > *"))!=null?a:[]).find(d=>d.id==="headlessui-portal-root"?!1:d.contains(F(N))&&d instanceof HTMLElement))!=null?p:null});q(ee,Z);let te=o(()=>w.value?!0:k.value),le=o(()=>{var e,a,p;return(p=Array.from((a=(e=E.value)==null?void 0:e.querySelectorAll("[data-headlessui-portal]"))!=null?a:[]).find(d=>d.contains(F(N))&&d instanceof HTMLElement))!=null?p:null});q(le,te),me({type:"Dialog",enabled:o(()=>f.value===0),element:c,onUpdate:(e,a)=>{if(a==="Dialog")return Y(e,{[W.Add]:()=>m.value+=1,[W.Remove]:()=>m.value-=1})}});let ae=he({name:"DialogDescription",slot:o(()=>({open:R.value}))}),M=y(null),h={titleId:M,panelRef:y(null),dialogState:f,setTitleId(e){M.value!==e&&(M.value=e)},close(){n("close",!1)}};se(j,h);let oe=o(()=>!(!k.value||w.value));ge(A,(e,a)=>{h.close(),ie(()=>a==null?void 0:a.focus())},oe);let re=o(()=>!(w.value||f.value!==0));fe((U=E.value)==null?void 0:U.defaultView,"keydown",e=>{re.value&&(e.defaultPrevented||e.key===De.Escape&&(e.preventDefault(),e.stopPropagation(),h.close()))});let ne=o(()=>!(K.value||f.value!==0||H));return de(E,ne,e=>{var a;return{containers:[...(a=e.containers)!=null?a:[],A]}}),pe(e=>{if(f.value!==0)return;let a=F(c);if(!a)return;let p=new ResizeObserver(d=>{for(let B of d){let D=B.target.getBoundingClientRect();D.x===0&&D.y===0&&D.width===0&&D.height===0&&h.close()}});p.observe(a),e(()=>p.disconnect())}),()=>{let{id:e,open:a,initialFocus:p,...d}=t,B={...l,ref:c,id:e,role:v.value,"aria-modal":f.value===0?!0:void 0,"aria-labelledby":M.value,"aria-describedby":ae.value},D={open:f.value===0};return g($,{force:!0},()=>[g(G,()=>g(Oe,{target:c.value},()=>g($,{force:!1},()=>g(P,{initialFocus:p,containers:A,features:k.value?Y(X.value,{parent:P.features.RestoreFocus,leaf:P.features.All&~P.features.FocusLock}):P.features.None},()=>g(J,{},()=>C({ourProps:B,theirProps:{...d,...l},slot:D,attrs:l,slots:u,visible:f.value===0,features:z.RenderStrategy|z.Static,name:"Dialog"})))))),g(Q)])}}}),qe=O({name:"DialogOverlay",props:{as:{type:[Object,String],default:"div"},id:{type:String,default:()=>`headlessui-dialog-overlay-${b()}`}},setup(t,{attrs:n,slots:l}){let u=T("DialogOverlay");function i(r){r.target===r.currentTarget&&(r.preventDefault(),r.stopPropagation(),u.close())}return()=>{let{id:r,...s}=t;return C({ourProps:{id:r,"aria-hidden":!0,onClick:i},theirProps:s,slot:{open:u.dialogState.value===0},attrs:n,slots:l,name:"DialogOverlay"})}}}),We=O({name:"DialogBackdrop",props:{as:{type:[Object,String],default:"div"},id:{type:String,default:()=>`headlessui-dialog-backdrop-${b()}`}},inheritAttrs:!1,setup(t,{attrs:n,slots:l,expose:u}){let i=T("DialogBackdrop"),r=y(null);return u({el:r,$el:r}),L(()=>{if(i.panelRef.value===null)throw new Error("A <DialogBackdrop /> component is being used, but a <DialogPanel /> component is missing.")}),()=>{let{id:s,...v}=t,m={id:s,ref:r,"aria-hidden":!0};return g($,{force:!0},()=>g(G,()=>C({ourProps:m,theirProps:{...n,...v},slot:{open:i.dialogState.value===0},attrs:n,slots:l,name:"DialogBackdrop"})))}}}),Ye=O({name:"DialogPanel",props:{as:{type:[Object,String],default:"div"},id:{type:String,default:()=>`headlessui-dialog-panel-${b()}`}},setup(t,{attrs:n,slots:l,expose:u}){let i=T("DialogPanel");u({el:i.panelRef,$el:i.panelRef});function r(s){s.stopPropagation()}return()=>{let{id:s,...v}=t,m={id:s,ref:i.panelRef,onClick:r};return C({ourProps:m,theirProps:v,slot:{open:i.dialogState.value===0},attrs:n,slots:l,name:"DialogPanel"})}}}),ze=O({name:"DialogTitle",props:{as:{type:[Object,String],default:"h2"},id:{type:String,default:()=>`headlessui-dialog-title-${b()}`}},setup(t,{attrs:n,slots:l}){let u=T("DialogTitle");return L(()=>{u.setTitleId(t.id),ue(()=>u.setTitleId(null))}),()=>{let{id:i,...r}=t;return C({ourProps:{id:i},theirProps:r,slot:{open:u.dialogState.value===0},attrs:n,slots:l,name:"DialogTitle"})}}}),Ge=Se;export{_e as Dialog,We as DialogBackdrop,Ge as DialogDescription,qe as DialogOverlay,Ye as DialogPanel,ze as DialogTitle}; | ||
import{computed as o,defineComponent as O,h as g,inject as q,nextTick as ie,onMounted as L,onUnmounted as ue,provide as se,ref as y,watchEffect as pe}from"vue";import{FocusTrap as P}from'../../components/focus-trap/focus-trap.js';import{useDocumentOverflowLockedEffect as de}from'../../hooks/document-overflow/use-document-overflow.js';import{useEventListener as fe}from'../../hooks/use-event-listener.js';import{useId as b}from'../../hooks/use-id.js';import{useInert as W}from'../../hooks/use-inert.js';import{useOutsideClick as ge}from'../../hooks/use-outside-click.js';import{useRootContainers as ce}from'../../hooks/use-root-containers.js';import{State as x,useOpenClosed as ve}from'../../internal/open-closed.js';import{ForcePortalRoot as $}from'../../internal/portal-force-root.js';import{StackMessage as Y,useStackProvider as me}from'../../internal/stack-context.js';import{Keys as De}from'../../keyboard.js';import{dom as F}from'../../utils/dom.js';import{match as _}from'../../utils/match.js';import{getOwnerDocument as ye}from'../../utils/owner.js';import{Features as z,render as C}from'../../utils/render.js';import{Description as Se,useDescriptions as he}from'../description/description.js';import{Portal as G,PortalGroup as Oe,useNestedPortals as Pe}from'../portal/portal.js';var be=(l=>(l[l.Open=0]="Open",l[l.Closed=1]="Closed",l))(be||{});let j=Symbol("DialogContext");function T(t){let n=q(j,null);if(n===null){let l=new Error(`<${t} /> is missing a parent <Dialog /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(l,T),l}return n}let I="DC8F892D-2EBD-447C-A4C8-A03058436FF4",qe=O({name:"Dialog",inheritAttrs:!1,props:{as:{type:[Object,String],default:"div"},static:{type:Boolean,default:!1},unmount:{type:Boolean,default:!0},open:{type:[Boolean,String],default:I},initialFocus:{type:Object,default:null},id:{type:String,default:()=>`headlessui-dialog-${b()}`},role:{type:String,default:"dialog"}},emits:{close:t=>!0},setup(t,{emit:n,attrs:l,slots:u,expose:i}){var U;let r=y(!1);L(()=>{r.value=!0});let s=!1,v=o(()=>t.role==="dialog"||t.role==="alertdialog"?t.role:(s||(s=!0,console.warn(`Invalid role [${v}] passed to <Dialog />. Only \`dialog\` and and \`alertdialog\` are supported. Using \`dialog\` instead.`)),"dialog")),m=y(0),S=ve(),R=o(()=>t.open===I&&S!==null?(S.value&x.Open)===x.Open:t.open),c=y(null),E=o(()=>ye(c));if(i({el:c,$el:c}),!(t.open!==I||S!==null))throw new Error("You forgot to provide an `open` prop to the `Dialog`.");if(typeof R.value!="boolean")throw new Error(`You provided an \`open\` prop to the \`Dialog\`, but the value is not a boolean. Received: ${R.value===I?void 0:t.open}`);let f=o(()=>r.value&&R.value?0:1),k=o(()=>f.value===0),w=o(()=>m.value>1),H=q(j,null)!==null,[V,J]=Pe(),{resolveContainers:A,mainTreeNodeRef:N,MainTreeNode:Q}=ce({portals:V,defaultContainers:[o(()=>{var e;return(e=h.panelRef.value)!=null?e:c.value})]}),X=o(()=>w.value?"parent":"leaf"),K=o(()=>S!==null?(S.value&x.Closing)===x.Closing:!1),Z=o(()=>H||K.value?!1:k.value),ee=o(()=>{var e,a,p;return(p=Array.from((a=(e=E.value)==null?void 0:e.querySelectorAll("body > *"))!=null?a:[]).find(d=>d.id==="headlessui-portal-root"?!1:d.contains(F(N))&&d instanceof HTMLElement))!=null?p:null});W(ee,Z);let te=o(()=>w.value?!0:k.value),le=o(()=>{var e,a,p;return(p=Array.from((a=(e=E.value)==null?void 0:e.querySelectorAll("[data-headlessui-portal]"))!=null?a:[]).find(d=>d.contains(F(N))&&d instanceof HTMLElement))!=null?p:null});W(le,te),me({type:"Dialog",enabled:o(()=>f.value===0),element:c,onUpdate:(e,a)=>{if(a==="Dialog")return _(e,{[Y.Add]:()=>m.value+=1,[Y.Remove]:()=>m.value-=1})}});let ae=he({name:"DialogDescription",slot:o(()=>({open:R.value}))}),M=y(null),h={titleId:M,panelRef:y(null),dialogState:f,setTitleId(e){M.value!==e&&(M.value=e)},close(){n("close",!1)}};se(j,h);let oe=o(()=>!(!k.value||w.value));ge(A,(e,a)=>{e.preventDefault(),h.close(),ie(()=>a==null?void 0:a.focus())},oe);let re=o(()=>!(w.value||f.value!==0));fe((U=E.value)==null?void 0:U.defaultView,"keydown",e=>{re.value&&(e.defaultPrevented||e.key===De.Escape&&(e.preventDefault(),e.stopPropagation(),h.close()))});let ne=o(()=>!(K.value||f.value!==0||H));return de(E,ne,e=>{var a;return{containers:[...(a=e.containers)!=null?a:[],A]}}),pe(e=>{if(f.value!==0)return;let a=F(c);if(!a)return;let p=new ResizeObserver(d=>{for(let B of d){let D=B.target.getBoundingClientRect();D.x===0&&D.y===0&&D.width===0&&D.height===0&&h.close()}});p.observe(a),e(()=>p.disconnect())}),()=>{let{id:e,open:a,initialFocus:p,...d}=t,B={...l,ref:c,id:e,role:v.value,"aria-modal":f.value===0?!0:void 0,"aria-labelledby":M.value,"aria-describedby":ae.value},D={open:f.value===0};return g($,{force:!0},()=>[g(G,()=>g(Oe,{target:c.value},()=>g($,{force:!1},()=>g(P,{initialFocus:p,containers:A,features:k.value?_(X.value,{parent:P.features.RestoreFocus,leaf:P.features.All&~P.features.FocusLock}):P.features.None},()=>g(J,{},()=>C({ourProps:B,theirProps:{...d,...l},slot:D,attrs:l,slots:u,visible:f.value===0,features:z.RenderStrategy|z.Static,name:"Dialog"})))))),g(Q)])}}}),We=O({name:"DialogOverlay",props:{as:{type:[Object,String],default:"div"},id:{type:String,default:()=>`headlessui-dialog-overlay-${b()}`}},setup(t,{attrs:n,slots:l}){let u=T("DialogOverlay");function i(r){r.target===r.currentTarget&&(r.preventDefault(),r.stopPropagation(),u.close())}return()=>{let{id:r,...s}=t;return C({ourProps:{id:r,"aria-hidden":!0,onClick:i},theirProps:s,slot:{open:u.dialogState.value===0},attrs:n,slots:l,name:"DialogOverlay"})}}}),Ye=O({name:"DialogBackdrop",props:{as:{type:[Object,String],default:"div"},id:{type:String,default:()=>`headlessui-dialog-backdrop-${b()}`}},inheritAttrs:!1,setup(t,{attrs:n,slots:l,expose:u}){let i=T("DialogBackdrop"),r=y(null);return u({el:r,$el:r}),L(()=>{if(i.panelRef.value===null)throw new Error("A <DialogBackdrop /> component is being used, but a <DialogPanel /> component is missing.")}),()=>{let{id:s,...v}=t,m={id:s,ref:r,"aria-hidden":!0};return g($,{force:!0},()=>g(G,()=>C({ourProps:m,theirProps:{...n,...v},slot:{open:i.dialogState.value===0},attrs:n,slots:l,name:"DialogBackdrop"})))}}}),_e=O({name:"DialogPanel",props:{as:{type:[Object,String],default:"div"},id:{type:String,default:()=>`headlessui-dialog-panel-${b()}`}},setup(t,{attrs:n,slots:l,expose:u}){let i=T("DialogPanel");u({el:i.panelRef,$el:i.panelRef});function r(s){s.stopPropagation()}return()=>{let{id:s,...v}=t,m={id:s,ref:i.panelRef,onClick:r};return C({ourProps:m,theirProps:v,slot:{open:i.dialogState.value===0},attrs:n,slots:l,name:"DialogPanel"})}}}),ze=O({name:"DialogTitle",props:{as:{type:[Object,String],default:"h2"},id:{type:String,default:()=>`headlessui-dialog-title-${b()}`}},setup(t,{attrs:n,slots:l}){let u=T("DialogTitle");return L(()=>{u.setTitleId(t.id),ue(()=>u.setTitleId(null))}),()=>{let{id:i,...r}=t;return C({ourProps:{id:i},theirProps:r,slot:{open:u.dialogState.value===0},attrs:n,slots:l,name:"DialogTitle"})}}}),Ge=Se;export{qe as Dialog,Ye as DialogBackdrop,Ge as DialogDescription,We as DialogOverlay,_e as DialogPanel,ze as DialogTitle}; |
@@ -120,3 +120,3 @@ import { type PropType, type Ref } from 'vue'; | ||
[key: string]: any; | ||
}>> & {} & {} & import("vue").ComponentCustomProperties; | ||
}>> & {} & import("vue").ComponentCustomProperties; | ||
__isFragment?: undefined; | ||
@@ -123,0 +123,0 @@ __isTeleport?: undefined; |
@@ -1,1 +0,1 @@ | ||
import{computed as L,defineComponent as I,Fragment as j,h as R,onMounted as M,onUnmounted as h,ref as E,watch as g,watchEffect as K}from"vue";import{useEventListener as U}from'../../hooks/use-event-listener.js';import{Direction as y,useTabDirection as _}from'../../hooks/use-tab-direction.js';import{Features as k,Hidden as D}from'../../internal/hidden.js';import{history as C}from'../../utils/active-element-history.js';import{dom as c}from'../../utils/dom.js';import{Focus as v,focusElement as p,focusIn as b,FocusResult as q}from'../../utils/focus-management.js';import{match as P}from'../../utils/match.js';import{microTask as S}from'../../utils/micro-task.js';import{getOwnerDocument as x}from'../../utils/owner.js';import{render as G}from'../../utils/render.js';function B(t){if(!t)return new Set;if(typeof t=="function")return new Set(t());let n=new Set;for(let r of t.value){let l=c(r);l instanceof HTMLElement&&n.add(l)}return n}var A=(e=>(e[e.None=1]="None",e[e.InitialFocus=2]="InitialFocus",e[e.TabLock=4]="TabLock",e[e.FocusLock=8]="FocusLock",e[e.RestoreFocus=16]="RestoreFocus",e[e.All=30]="All",e))(A||{});let ue=Object.assign(I({name:"FocusTrap",props:{as:{type:[Object,String],default:"div"},initialFocus:{type:Object,default:null},features:{type:Number,default:30},containers:{type:[Object,Function],default:E(new Set)}},inheritAttrs:!1,setup(t,{attrs:n,slots:r,expose:l}){let o=E(null);l({el:o,$el:o});let i=L(()=>x(o)),e=E(!1);M(()=>e.value=!0),h(()=>e.value=!1),$({ownerDocument:i},L(()=>e.value&&Boolean(t.features&16)));let m=z({ownerDocument:i,container:o,initialFocus:L(()=>t.initialFocus)},L(()=>e.value&&Boolean(t.features&2)));J({ownerDocument:i,container:o,containers:t.containers,previousActiveElement:m},L(()=>e.value&&Boolean(t.features&8)));let f=_();function a(u){let T=c(o);if(!T)return;(w=>w())(()=>{P(f.value,{[y.Forwards]:()=>{b(T,v.First,{skipElements:[u.relatedTarget]})},[y.Backwards]:()=>{b(T,v.Last,{skipElements:[u.relatedTarget]})}})})}let s=E(!1);function F(u){u.key==="Tab"&&(s.value=!0,requestAnimationFrame(()=>{s.value=!1}))}function H(u){if(!e.value)return;let T=B(t.containers);c(o)instanceof HTMLElement&&T.add(c(o));let d=u.relatedTarget;d instanceof HTMLElement&&d.dataset.headlessuiFocusGuard!=="true"&&(N(T,d)||(s.value?b(c(o),P(f.value,{[y.Forwards]:()=>v.Next,[y.Backwards]:()=>v.Previous})|v.WrapAround,{relativeTo:u.target}):u.target instanceof HTMLElement&&p(u.target)))}return()=>{let u={},T={ref:o,onKeydown:F,onFocusout:H},{features:d,initialFocus:w,containers:Q,...O}=t;return R(j,[Boolean(d&4)&&R(D,{as:"button",type:"button","data-headlessui-focus-guard":!0,onFocus:a,features:k.Focusable}),G({ourProps:T,theirProps:{...n,...O},slot:u,attrs:n,slots:r,name:"FocusTrap"}),Boolean(d&4)&&R(D,{as:"button",type:"button","data-headlessui-focus-guard":!0,onFocus:a,features:k.Focusable})])}}}),{features:A});function W(t){let n=E(C.slice());return g([t],([r],[l])=>{l===!0&&r===!1?S(()=>{n.value.splice(0)}):l===!1&&r===!0&&(n.value=C.slice())},{flush:"post"}),()=>{var r;return(r=n.value.find(l=>l!=null&&l.isConnected))!=null?r:null}}function $({ownerDocument:t},n){let r=W(n);M(()=>{K(()=>{var l,o;n.value||((l=t.value)==null?void 0:l.activeElement)===((o=t.value)==null?void 0:o.body)&&p(r())},{flush:"post"})}),h(()=>{n.value&&p(r())})}function z({ownerDocument:t,container:n,initialFocus:r},l){let o=E(null),i=E(!1);return M(()=>i.value=!0),h(()=>i.value=!1),M(()=>{g([n,r,l],(e,m)=>{if(e.every((a,s)=>(m==null?void 0:m[s])===a)||!l.value)return;let f=c(n);f&&S(()=>{var F,H;if(!i.value)return;let a=c(r),s=(F=t.value)==null?void 0:F.activeElement;if(a){if(a===s){o.value=s;return}}else if(f.contains(s)){o.value=s;return}a?p(a):b(f,v.First|v.NoScroll)===q.Error&&console.warn("There are no focusable elements inside the <FocusTrap />"),o.value=(H=t.value)==null?void 0:H.activeElement})},{immediate:!0,flush:"post"})}),o}function J({ownerDocument:t,container:n,containers:r,previousActiveElement:l},o){var i;U((i=t.value)==null?void 0:i.defaultView,"focus",e=>{if(!o.value)return;let m=B(r);c(n)instanceof HTMLElement&&m.add(c(n));let f=l.value;if(!f)return;let a=e.target;a&&a instanceof HTMLElement?N(m,a)?(l.value=a,p(a)):(e.preventDefault(),e.stopPropagation(),p(f)):p(l.value)},!0)}function N(t,n){for(let r of t)if(r.contains(n))return!0;return!1}export{ue as FocusTrap}; | ||
import{Fragment as I,computed as L,defineComponent as j,h as R,onMounted as M,onUnmounted as h,ref as E,watch as g,watchEffect as K}from"vue";import{useEventListener as U}from'../../hooks/use-event-listener.js';import{Direction as y,useTabDirection as _}from'../../hooks/use-tab-direction.js';import{Hidden as k,Features as D}from'../../internal/hidden.js';import{history as C}from'../../utils/active-element-history.js';import{dom as c}from'../../utils/dom.js';import{Focus as v,FocusResult as q,focusElement as p,focusIn as b}from'../../utils/focus-management.js';import{match as P}from'../../utils/match.js';import{microTask as S}from'../../utils/micro-task.js';import{getOwnerDocument as x}from'../../utils/owner.js';import{render as G}from'../../utils/render.js';function B(t){if(!t)return new Set;if(typeof t=="function")return new Set(t());let n=new Set;for(let r of t.value){let l=c(r);l instanceof HTMLElement&&n.add(l)}return n}var A=(e=>(e[e.None=1]="None",e[e.InitialFocus=2]="InitialFocus",e[e.TabLock=4]="TabLock",e[e.FocusLock=8]="FocusLock",e[e.RestoreFocus=16]="RestoreFocus",e[e.All=30]="All",e))(A||{});let ue=Object.assign(j({name:"FocusTrap",props:{as:{type:[Object,String],default:"div"},initialFocus:{type:Object,default:null},features:{type:Number,default:30},containers:{type:[Object,Function],default:E(new Set)}},inheritAttrs:!1,setup(t,{attrs:n,slots:r,expose:l}){let o=E(null);l({el:o,$el:o});let i=L(()=>x(o)),e=E(!1);M(()=>e.value=!0),h(()=>e.value=!1),$({ownerDocument:i},L(()=>e.value&&!!(t.features&16)));let m=z({ownerDocument:i,container:o,initialFocus:L(()=>t.initialFocus)},L(()=>e.value&&!!(t.features&2)));J({ownerDocument:i,container:o,containers:t.containers,previousActiveElement:m},L(()=>e.value&&!!(t.features&8)));let f=_();function a(u){let T=c(o);if(!T)return;(w=>w())(()=>{P(f.value,{[y.Forwards]:()=>{b(T,v.First,{skipElements:[u.relatedTarget]})},[y.Backwards]:()=>{b(T,v.Last,{skipElements:[u.relatedTarget]})}})})}let s=E(!1);function F(u){u.key==="Tab"&&(s.value=!0,requestAnimationFrame(()=>{s.value=!1}))}function H(u){if(!e.value)return;let T=B(t.containers);c(o)instanceof HTMLElement&&T.add(c(o));let d=u.relatedTarget;d instanceof HTMLElement&&d.dataset.headlessuiFocusGuard!=="true"&&(N(T,d)||(s.value?b(c(o),P(f.value,{[y.Forwards]:()=>v.Next,[y.Backwards]:()=>v.Previous})|v.WrapAround,{relativeTo:u.target}):u.target instanceof HTMLElement&&p(u.target)))}return()=>{let u={},T={ref:o,onKeydown:F,onFocusout:H},{features:d,initialFocus:w,containers:Q,...O}=t;return R(I,[!!(d&4)&&R(k,{as:"button",type:"button","data-headlessui-focus-guard":!0,onFocus:a,features:D.Focusable}),G({ourProps:T,theirProps:{...n,...O},slot:u,attrs:n,slots:r,name:"FocusTrap"}),!!(d&4)&&R(k,{as:"button",type:"button","data-headlessui-focus-guard":!0,onFocus:a,features:D.Focusable})])}}}),{features:A});function W(t){let n=E(C.slice());return g([t],([r],[l])=>{l===!0&&r===!1?S(()=>{n.value.splice(0)}):l===!1&&r===!0&&(n.value=C.slice())},{flush:"post"}),()=>{var r;return(r=n.value.find(l=>l!=null&&l.isConnected))!=null?r:null}}function $({ownerDocument:t},n){let r=W(n);M(()=>{K(()=>{var l,o;n.value||((l=t.value)==null?void 0:l.activeElement)===((o=t.value)==null?void 0:o.body)&&p(r())},{flush:"post"})}),h(()=>{n.value&&p(r())})}function z({ownerDocument:t,container:n,initialFocus:r},l){let o=E(null),i=E(!1);return M(()=>i.value=!0),h(()=>i.value=!1),M(()=>{g([n,r,l],(e,m)=>{if(e.every((a,s)=>(m==null?void 0:m[s])===a)||!l.value)return;let f=c(n);f&&S(()=>{var F,H;if(!i.value)return;let a=c(r),s=(F=t.value)==null?void 0:F.activeElement;if(a){if(a===s){o.value=s;return}}else if(f.contains(s)){o.value=s;return}a?p(a):b(f,v.First|v.NoScroll)===q.Error&&console.warn("There are no focusable elements inside the <FocusTrap />"),o.value=(H=t.value)==null?void 0:H.activeElement})},{immediate:!0,flush:"post"})}),o}function J({ownerDocument:t,container:n,containers:r,previousActiveElement:l},o){var i;U((i=t.value)==null?void 0:i.defaultView,"focus",e=>{if(!o.value)return;let m=B(r);c(n)instanceof HTMLElement&&m.add(c(n));let f=l.value;if(!f)return;let a=e.target;a&&a instanceof HTMLElement?N(m,a)?(l.value=a,p(a)):(e.preventDefault(),e.stopPropagation(),p(f)):p(l.value)},!0)}function N(t,n){for(let r of t)if(r.contains(n))return!0;return!1}export{ue as FocusTrap}; |
@@ -38,5 +38,5 @@ import { type ComputedRef } from 'vue'; | ||
}>>, { | ||
passive: boolean; | ||
id: string; | ||
passive: boolean; | ||
as: string | Record<string, any>; | ||
}>; |
@@ -86,2 +86,3 @@ import { type PropType } from 'vue'; | ||
disabled: boolean; | ||
horizontal: boolean; | ||
by: string | Function; | ||
@@ -91,3 +92,2 @@ modelValue: string | number | boolean | object | null; | ||
multiple: boolean; | ||
horizontal: boolean; | ||
}>; | ||
@@ -94,0 +94,0 @@ export declare let ListboxLabel: import("vue").DefineComponent<{ |
@@ -1,1 +0,1 @@ | ||
import{computed as S,defineComponent as E,Fragment as z,h as N,inject as _,nextTick as V,onMounted as K,onUnmounted as q,provide as W,ref as D,toRaw as R,watch as H,watchEffect as G}from"vue";import{useControllable as J}from'../../hooks/use-controllable.js';import{useId as F}from'../../hooks/use-id.js';import{useOutsideClick as X}from'../../hooks/use-outside-click.js';import{useResolveButtonType as Y}from'../../hooks/use-resolve-button-type.js';import{useTextValue as Z}from'../../hooks/use-text-value.js';import{useTrackedPointer as ee}from'../../hooks/use-tracked-pointer.js';import{Features as te,Hidden as oe}from'../../internal/hidden.js';import{State as B,useOpenClosed as ie,useOpenClosedProvider as ae}from'../../internal/open-closed.js';import{Keys as p}from'../../keyboard.js';import{calculateActiveIndex as ne,Focus as g}from'../../utils/calculate-active-index.js';import{dom as c}from'../../utils/dom.js';import{FocusableMode as le,isFocusableElement as ue,sortByDomNode as re}from'../../utils/focus-management.js';import{objectToFormEntries as se}from'../../utils/form.js';import{match as C}from'../../utils/match.js';import{compact as de,Features as U,omit as fe,render as j}from'../../utils/render.js';function pe(t,v){return t===v}var ce=(l=>(l[l.Open=0]="Open",l[l.Closed=1]="Closed",l))(ce||{}),ve=(l=>(l[l.Single=0]="Single",l[l.Multi=1]="Multi",l))(ve||{}),be=(l=>(l[l.Pointer=0]="Pointer",l[l.Other=1]="Other",l))(be||{});function me(t){requestAnimationFrame(()=>requestAnimationFrame(t))}let $=Symbol("ListboxContext");function A(t){let v=_($,null);if(v===null){let l=new Error(`<${t} /> is missing a parent <Listbox /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(l,A),l}return v}let Ie=E({name:"Listbox",emits:{"update:modelValue":t=>!0},props:{as:{type:[Object,String],default:"template"},disabled:{type:[Boolean],default:!1},by:{type:[String,Function],default:()=>pe},horizontal:{type:[Boolean],default:!1},modelValue:{type:[Object,String,Number,Boolean],default:void 0},defaultValue:{type:[Object,String,Number,Boolean],default:void 0},form:{type:String,optional:!0},name:{type:String,optional:!0},multiple:{type:[Boolean],default:!1}},inheritAttrs:!1,setup(t,{slots:v,attrs:l,emit:L}){let e=D(1),d=D(null),b=D(null),m=D(null),f=D([]),o=D(""),i=D(null),T=D(1);function k(a=n=>n){let n=i.value!==null?f.value[i.value]:null,u=re(a(f.value.slice()),O=>c(O.dataRef.domRef)),s=n?u.indexOf(n):null;return s===-1&&(s=null),{options:u,activeOptionIndex:s}}let y=S(()=>t.multiple?1:0),[h,M]=J(S(()=>t.modelValue),a=>L("update:modelValue",a),S(()=>t.defaultValue)),w=S(()=>h.value===void 0?C(y.value,{[1]:[],[0]:void 0}):h.value),r={listboxState:e,value:w,mode:y,compare(a,n){if(typeof t.by=="string"){let u=t.by;return(a==null?void 0:a[u])===(n==null?void 0:n[u])}return t.by(a,n)},orientation:S(()=>t.horizontal?"horizontal":"vertical"),labelRef:d,buttonRef:b,optionsRef:m,disabled:S(()=>t.disabled),options:f,searchQuery:o,activeOptionIndex:i,activationTrigger:T,closeListbox(){t.disabled||e.value!==1&&(e.value=1,i.value=null)},openListbox(){t.disabled||e.value!==0&&(e.value=0)},goToOption(a,n,u){if(t.disabled||e.value===1)return;let s=k(),O=ne(a===g.Specific?{focus:g.Specific,id:n}:{focus:a},{resolveItems:()=>s.options,resolveActiveIndex:()=>s.activeOptionIndex,resolveId:P=>P.id,resolveDisabled:P=>P.dataRef.disabled});o.value="",i.value=O,T.value=u!=null?u:1,f.value=s.options},search(a){if(t.disabled||e.value===1)return;let u=o.value!==""?0:1;o.value+=a.toLowerCase();let O=(i.value!==null?f.value.slice(i.value+u).concat(f.value.slice(0,i.value+u)):f.value).find(I=>I.dataRef.textValue.startsWith(o.value)&&!I.dataRef.disabled),P=O?f.value.indexOf(O):-1;P===-1||P===i.value||(i.value=P,T.value=1)},clearSearch(){t.disabled||e.value!==1&&o.value!==""&&(o.value="")},registerOption(a,n){let u=k(s=>[...s,{id:a,dataRef:n}]);f.value=u.options,i.value=u.activeOptionIndex},unregisterOption(a){let n=k(u=>{let s=u.findIndex(O=>O.id===a);return s!==-1&&u.splice(s,1),u});f.value=n.options,i.value=n.activeOptionIndex,T.value=1},theirOnChange(a){t.disabled||M(a)},select(a){t.disabled||M(C(y.value,{[0]:()=>a,[1]:()=>{let n=R(r.value.value).slice(),u=R(a),s=n.findIndex(O=>r.compare(u,R(O)));return s===-1?n.push(u):n.splice(s,1),n}}))}};X([b,m],(a,n)=>{var u;r.closeListbox(),ue(n,le.Loose)||(a.preventDefault(),(u=c(b))==null||u.focus())},S(()=>e.value===0)),W($,r),ae(S(()=>C(e.value,{[0]:B.Open,[1]:B.Closed})));let x=S(()=>{var a;return(a=c(b))==null?void 0:a.closest("form")});return K(()=>{H([x],()=>{if(!x.value||t.defaultValue===void 0)return;function a(){r.theirOnChange(t.defaultValue)}return x.value.addEventListener("reset",a),()=>{var n;(n=x.value)==null||n.removeEventListener("reset",a)}},{immediate:!0})}),()=>{let{name:a,modelValue:n,disabled:u,form:s,...O}=t,P={open:e.value===0,disabled:u,value:w.value};return N(z,[...a!=null&&w.value!=null?se({[a]:w.value}).map(([I,Q])=>N(oe,de({features:te.Hidden,key:I,as:"input",type:"hidden",hidden:!0,readOnly:!0,form:s,name:I,value:Q}))):[],j({ourProps:{},theirProps:{...l,...fe(O,["defaultValue","onUpdate:modelValue","horizontal","multiple","by"])},slot:P,slots:v,attrs:l,name:"Listbox"})])}}}),Ee=E({name:"ListboxLabel",props:{as:{type:[Object,String],default:"label"},id:{type:String,default:()=>`headlessui-listbox-label-${F()}`}},setup(t,{attrs:v,slots:l}){let L=A("ListboxLabel");function e(){var d;(d=c(L.buttonRef))==null||d.focus({preventScroll:!0})}return()=>{let d={open:L.listboxState.value===0,disabled:L.disabled.value},{id:b,...m}=t,f={id:b,ref:L.labelRef,onClick:e};return j({ourProps:f,theirProps:m,slot:d,attrs:v,slots:l,name:"ListboxLabel"})}}}),je=E({name:"ListboxButton",props:{as:{type:[Object,String],default:"button"},id:{type:String,default:()=>`headlessui-listbox-button-${F()}`}},setup(t,{attrs:v,slots:l,expose:L}){let e=A("ListboxButton");L({el:e.buttonRef,$el:e.buttonRef});function d(o){switch(o.key){case p.Space:case p.Enter:case p.ArrowDown:o.preventDefault(),e.openListbox(),V(()=>{var i;(i=c(e.optionsRef))==null||i.focus({preventScroll:!0}),e.value.value||e.goToOption(g.First)});break;case p.ArrowUp:o.preventDefault(),e.openListbox(),V(()=>{var i;(i=c(e.optionsRef))==null||i.focus({preventScroll:!0}),e.value.value||e.goToOption(g.Last)});break}}function b(o){switch(o.key){case p.Space:o.preventDefault();break}}function m(o){e.disabled.value||(e.listboxState.value===0?(e.closeListbox(),V(()=>{var i;return(i=c(e.buttonRef))==null?void 0:i.focus({preventScroll:!0})})):(o.preventDefault(),e.openListbox(),me(()=>{var i;return(i=c(e.optionsRef))==null?void 0:i.focus({preventScroll:!0})})))}let f=Y(S(()=>({as:t.as,type:v.type})),e.buttonRef);return()=>{var y,h;let o={open:e.listboxState.value===0,disabled:e.disabled.value,value:e.value.value},{id:i,...T}=t,k={ref:e.buttonRef,id:i,type:f.value,"aria-haspopup":"listbox","aria-controls":(y=c(e.optionsRef))==null?void 0:y.id,"aria-expanded":e.listboxState.value===0,"aria-labelledby":e.labelRef.value?[(h=c(e.labelRef))==null?void 0:h.id,i].join(" "):void 0,disabled:e.disabled.value===!0?!0:void 0,onKeydown:d,onKeyup:b,onClick:m};return j({ourProps:k,theirProps:T,slot:o,attrs:v,slots:l,name:"ListboxButton"})}}}),Ae=E({name:"ListboxOptions",props:{as:{type:[Object,String],default:"ul"},static:{type:Boolean,default:!1},unmount:{type:Boolean,default:!0},id:{type:String,default:()=>`headlessui-listbox-options-${F()}`}},setup(t,{attrs:v,slots:l,expose:L}){let e=A("ListboxOptions"),d=D(null);L({el:e.optionsRef,$el:e.optionsRef});function b(o){switch(d.value&&clearTimeout(d.value),o.key){case p.Space:if(e.searchQuery.value!=="")return o.preventDefault(),o.stopPropagation(),e.search(o.key);case p.Enter:if(o.preventDefault(),o.stopPropagation(),e.activeOptionIndex.value!==null){let i=e.options.value[e.activeOptionIndex.value];e.select(i.dataRef.value)}e.mode.value===0&&(e.closeListbox(),V(()=>{var i;return(i=c(e.buttonRef))==null?void 0:i.focus({preventScroll:!0})}));break;case C(e.orientation.value,{vertical:p.ArrowDown,horizontal:p.ArrowRight}):return o.preventDefault(),o.stopPropagation(),e.goToOption(g.Next);case C(e.orientation.value,{vertical:p.ArrowUp,horizontal:p.ArrowLeft}):return o.preventDefault(),o.stopPropagation(),e.goToOption(g.Previous);case p.Home:case p.PageUp:return o.preventDefault(),o.stopPropagation(),e.goToOption(g.First);case p.End:case p.PageDown:return o.preventDefault(),o.stopPropagation(),e.goToOption(g.Last);case p.Escape:o.preventDefault(),o.stopPropagation(),e.closeListbox(),V(()=>{var i;return(i=c(e.buttonRef))==null?void 0:i.focus({preventScroll:!0})});break;case p.Tab:o.preventDefault(),o.stopPropagation();break;default:o.key.length===1&&(e.search(o.key),d.value=setTimeout(()=>e.clearSearch(),350));break}}let m=ie(),f=S(()=>m!==null?(m.value&B.Open)===B.Open:e.listboxState.value===0);return()=>{var y,h,M,w;let o={open:e.listboxState.value===0},{id:i,...T}=t,k={"aria-activedescendant":e.activeOptionIndex.value===null||(y=e.options.value[e.activeOptionIndex.value])==null?void 0:y.id,"aria-multiselectable":e.mode.value===1?!0:void 0,"aria-labelledby":(w=(h=c(e.labelRef))==null?void 0:h.id)!=null?w:(M=c(e.buttonRef))==null?void 0:M.id,"aria-orientation":e.orientation.value,id:i,onKeydown:b,role:"listbox",tabIndex:0,ref:e.optionsRef};return j({ourProps:k,theirProps:T,slot:o,attrs:v,slots:l,features:U.RenderStrategy|U.Static,visible:f.value,name:"ListboxOptions"})}}}),Fe=E({name:"ListboxOption",props:{as:{type:[Object,String],default:"li"},value:{type:[Object,String,Number,Boolean]},disabled:{type:Boolean,default:!1},id:{type:String,default:()=>`headlessui-listbox.option-${F()}`}},setup(t,{slots:v,attrs:l,expose:L}){let e=A("ListboxOption"),d=D(null);L({el:d,$el:d});let b=S(()=>e.activeOptionIndex.value!==null?e.options.value[e.activeOptionIndex.value].id===t.id:!1),m=S(()=>C(e.mode.value,{[0]:()=>e.compare(R(e.value.value),R(t.value)),[1]:()=>R(e.value.value).some(r=>e.compare(R(r),R(t.value)))})),f=S(()=>C(e.mode.value,{[1]:()=>{var x;let r=R(e.value.value);return((x=e.options.value.find(a=>r.some(n=>e.compare(R(n),R(a.dataRef.value)))))==null?void 0:x.id)===t.id},[0]:()=>m.value})),o=Z(d),i=S(()=>({disabled:t.disabled,value:t.value,get textValue(){return o()},domRef:d}));K(()=>e.registerOption(t.id,i)),q(()=>e.unregisterOption(t.id)),K(()=>{H([e.listboxState,m],()=>{e.listboxState.value===0&&m.value&&C(e.mode.value,{[1]:()=>{f.value&&e.goToOption(g.Specific,t.id)},[0]:()=>{e.goToOption(g.Specific,t.id)}})},{immediate:!0})}),G(()=>{e.listboxState.value===0&&b.value&&e.activationTrigger.value!==0&&V(()=>{var r,x;return(x=(r=c(d))==null?void 0:r.scrollIntoView)==null?void 0:x.call(r,{block:"nearest"})})});function T(r){if(t.disabled)return r.preventDefault();e.select(t.value),e.mode.value===0&&(e.closeListbox(),V(()=>{var x;return(x=c(e.buttonRef))==null?void 0:x.focus({preventScroll:!0})}))}function k(){if(t.disabled)return e.goToOption(g.Nothing);e.goToOption(g.Specific,t.id)}let y=ee();function h(r){y.update(r)}function M(r){y.wasMoved(r)&&(t.disabled||b.value||e.goToOption(g.Specific,t.id,0))}function w(r){y.wasMoved(r)&&(t.disabled||b.value&&e.goToOption(g.Nothing))}return()=>{let{disabled:r}=t,x={active:b.value,selected:m.value,disabled:r},{id:a,value:n,disabled:u,...s}=t,O={id:a,ref:d,role:"option",tabIndex:r===!0?void 0:-1,"aria-disabled":r===!0?!0:void 0,"aria-selected":m.value,disabled:void 0,onClick:T,onFocus:k,onPointerenter:h,onMouseenter:h,onPointermove:M,onMousemove:M,onPointerleave:w,onMouseleave:w};return j({ourProps:O,theirProps:s,slot:x,attrs:l,slots:v,name:"ListboxOption"})}}});export{Ie as Listbox,je as ListboxButton,Ee as ListboxLabel,Fe as ListboxOption,Ae as ListboxOptions}; | ||
import{Fragment as z,computed as x,defineComponent as E,h as N,inject as _,nextTick as C,onMounted as K,onUnmounted as q,provide as W,ref as w,toRaw as R,watch as H,watchEffect as G}from"vue";import{useControllable as J}from'../../hooks/use-controllable.js';import{useId as F}from'../../hooks/use-id.js';import{useOutsideClick as X}from'../../hooks/use-outside-click.js';import{useResolveButtonType as Y}from'../../hooks/use-resolve-button-type.js';import{useTextValue as Z}from'../../hooks/use-text-value.js';import{useTrackedPointer as ee}from'../../hooks/use-tracked-pointer.js';import{Hidden as te,Features as oe}from'../../internal/hidden.js';import{State as B,useOpenClosed as ie,useOpenClosedProvider as ae}from'../../internal/open-closed.js';import{Keys as p}from'../../keyboard.js';import{Focus as g,calculateActiveIndex as ne}from'../../utils/calculate-active-index.js';import{dom as S}from'../../utils/dom.js';import{FocusableMode as le,isFocusableElement as ue,sortByDomNode as re}from'../../utils/focus-management.js';import{objectToFormEntries as se}from'../../utils/form.js';import{match as P}from'../../utils/match.js';import{Features as U,compact as de,omit as fe,render as j}from'../../utils/render.js';function pe(t,c){return t===c}var ce=(u=>(u[u.Open=0]="Open",u[u.Closed=1]="Closed",u))(ce||{}),ve=(u=>(u[u.Single=0]="Single",u[u.Multi=1]="Multi",u))(ve||{}),be=(u=>(u[u.Pointer=0]="Pointer",u[u.Other=1]="Other",u))(be||{});function me(t){requestAnimationFrame(()=>requestAnimationFrame(t))}let $=Symbol("ListboxContext");function A(t){let c=_($,null);if(c===null){let u=new Error(`<${t} /> is missing a parent <Listbox /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(u,A),u}return c}let Ie=E({name:"Listbox",emits:{"update:modelValue":t=>!0},props:{as:{type:[Object,String],default:"template"},disabled:{type:[Boolean],default:!1},by:{type:[String,Function],default:()=>pe},horizontal:{type:[Boolean],default:!1},modelValue:{type:[Object,String,Number,Boolean],default:void 0},defaultValue:{type:[Object,String,Number,Boolean],default:void 0},form:{type:String,optional:!0},name:{type:String,optional:!0},multiple:{type:[Boolean],default:!1}},inheritAttrs:!1,setup(t,{slots:c,attrs:u,emit:L}){let e=w(1),d=w(null),v=w(null),b=w(null),f=w([]),o=w(""),i=w(null),T=w(1);function D(a=n=>n){let n=i.value!==null?f.value[i.value]:null,l=re(a(f.value.slice()),O=>S(O.dataRef.domRef)),s=n?l.indexOf(n):null;return s===-1&&(s=null),{options:l,activeOptionIndex:s}}let y=x(()=>t.multiple?1:0),[h,V]=J(x(()=>t.modelValue),a=>L("update:modelValue",a),x(()=>t.defaultValue)),M=x(()=>h.value===void 0?P(y.value,{[1]:[],[0]:void 0}):h.value),r={listboxState:e,value:M,mode:y,compare(a,n){if(typeof t.by=="string"){let l=t.by;return(a==null?void 0:a[l])===(n==null?void 0:n[l])}return t.by(a,n)},orientation:x(()=>t.horizontal?"horizontal":"vertical"),labelRef:d,buttonRef:v,optionsRef:b,disabled:x(()=>t.disabled),options:f,searchQuery:o,activeOptionIndex:i,activationTrigger:T,closeListbox(){t.disabled||e.value!==1&&(e.value=1,i.value=null)},openListbox(){t.disabled||e.value!==0&&(e.value=0)},goToOption(a,n,l){if(t.disabled||e.value===1)return;let s=D(),O=ne(a===g.Specific?{focus:g.Specific,id:n}:{focus:a},{resolveItems:()=>s.options,resolveActiveIndex:()=>s.activeOptionIndex,resolveId:k=>k.id,resolveDisabled:k=>k.dataRef.disabled});o.value="",i.value=O,T.value=l!=null?l:1,f.value=s.options},search(a){if(t.disabled||e.value===1)return;let l=o.value!==""?0:1;o.value+=a.toLowerCase();let O=(i.value!==null?f.value.slice(i.value+l).concat(f.value.slice(0,i.value+l)):f.value).find(I=>I.dataRef.textValue.startsWith(o.value)&&!I.dataRef.disabled),k=O?f.value.indexOf(O):-1;k===-1||k===i.value||(i.value=k,T.value=1)},clearSearch(){t.disabled||e.value!==1&&o.value!==""&&(o.value="")},registerOption(a,n){let l=D(s=>[...s,{id:a,dataRef:n}]);f.value=l.options,i.value=l.activeOptionIndex},unregisterOption(a){let n=D(l=>{let s=l.findIndex(O=>O.id===a);return s!==-1&&l.splice(s,1),l});f.value=n.options,i.value=n.activeOptionIndex,T.value=1},theirOnChange(a){t.disabled||V(a)},select(a){t.disabled||V(P(y.value,{[0]:()=>a,[1]:()=>{let n=R(r.value.value).slice(),l=R(a),s=n.findIndex(O=>r.compare(l,R(O)));return s===-1?n.push(l):n.splice(s,1),n}}))}};X([v,b],(a,n)=>{var l;r.closeListbox(),ue(n,le.Loose)||(a.preventDefault(),(l=S(v))==null||l.focus())},x(()=>e.value===0)),W($,r),ae(x(()=>P(e.value,{[0]:B.Open,[1]:B.Closed})));let m=x(()=>{var a;return(a=S(v))==null?void 0:a.closest("form")});return K(()=>{H([m],()=>{if(!m.value||t.defaultValue===void 0)return;function a(){r.theirOnChange(t.defaultValue)}return m.value.addEventListener("reset",a),()=>{var n;(n=m.value)==null||n.removeEventListener("reset",a)}},{immediate:!0})}),()=>{let{name:a,modelValue:n,disabled:l,form:s,...O}=t,k={open:e.value===0,disabled:l,value:M.value};return N(z,[...a!=null&&M.value!=null?se({[a]:M.value}).map(([I,Q])=>N(te,de({features:oe.Hidden,key:I,as:"input",type:"hidden",hidden:!0,readOnly:!0,form:s,disabled:l,name:I,value:Q}))):[],j({ourProps:{},theirProps:{...u,...fe(O,["defaultValue","onUpdate:modelValue","horizontal","multiple","by"])},slot:k,slots:c,attrs:u,name:"Listbox"})])}}}),Ee=E({name:"ListboxLabel",props:{as:{type:[Object,String],default:"label"},id:{type:String,default:()=>`headlessui-listbox-label-${F()}`}},setup(t,{attrs:c,slots:u}){let L=A("ListboxLabel");function e(){var d;(d=S(L.buttonRef))==null||d.focus({preventScroll:!0})}return()=>{let d={open:L.listboxState.value===0,disabled:L.disabled.value},{id:v,...b}=t,f={id:v,ref:L.labelRef,onClick:e};return j({ourProps:f,theirProps:b,slot:d,attrs:c,slots:u,name:"ListboxLabel"})}}}),je=E({name:"ListboxButton",props:{as:{type:[Object,String],default:"button"},id:{type:String,default:()=>`headlessui-listbox-button-${F()}`}},setup(t,{attrs:c,slots:u,expose:L}){let e=A("ListboxButton");L({el:e.buttonRef,$el:e.buttonRef});function d(o){switch(o.key){case p.Space:case p.Enter:case p.ArrowDown:o.preventDefault(),e.openListbox(),C(()=>{var i;(i=S(e.optionsRef))==null||i.focus({preventScroll:!0}),e.value.value||e.goToOption(g.First)});break;case p.ArrowUp:o.preventDefault(),e.openListbox(),C(()=>{var i;(i=S(e.optionsRef))==null||i.focus({preventScroll:!0}),e.value.value||e.goToOption(g.Last)});break}}function v(o){switch(o.key){case p.Space:o.preventDefault();break}}function b(o){e.disabled.value||(e.listboxState.value===0?(e.closeListbox(),C(()=>{var i;return(i=S(e.buttonRef))==null?void 0:i.focus({preventScroll:!0})})):(o.preventDefault(),e.openListbox(),me(()=>{var i;return(i=S(e.optionsRef))==null?void 0:i.focus({preventScroll:!0})})))}let f=Y(x(()=>({as:t.as,type:c.type})),e.buttonRef);return()=>{var y,h;let o={open:e.listboxState.value===0,disabled:e.disabled.value,value:e.value.value},{id:i,...T}=t,D={ref:e.buttonRef,id:i,type:f.value,"aria-haspopup":"listbox","aria-controls":(y=S(e.optionsRef))==null?void 0:y.id,"aria-expanded":e.listboxState.value===0,"aria-labelledby":e.labelRef.value?[(h=S(e.labelRef))==null?void 0:h.id,i].join(" "):void 0,disabled:e.disabled.value===!0?!0:void 0,onKeydown:d,onKeyup:v,onClick:b};return j({ourProps:D,theirProps:T,slot:o,attrs:c,slots:u,name:"ListboxButton"})}}}),Ae=E({name:"ListboxOptions",props:{as:{type:[Object,String],default:"ul"},static:{type:Boolean,default:!1},unmount:{type:Boolean,default:!0},id:{type:String,default:()=>`headlessui-listbox-options-${F()}`}},setup(t,{attrs:c,slots:u,expose:L}){let e=A("ListboxOptions"),d=w(null);L({el:e.optionsRef,$el:e.optionsRef});function v(o){switch(d.value&&clearTimeout(d.value),o.key){case p.Space:if(e.searchQuery.value!=="")return o.preventDefault(),o.stopPropagation(),e.search(o.key);case p.Enter:if(o.preventDefault(),o.stopPropagation(),e.activeOptionIndex.value!==null){let i=e.options.value[e.activeOptionIndex.value];e.select(i.dataRef.value)}e.mode.value===0&&(e.closeListbox(),C(()=>{var i;return(i=S(e.buttonRef))==null?void 0:i.focus({preventScroll:!0})}));break;case P(e.orientation.value,{vertical:p.ArrowDown,horizontal:p.ArrowRight}):return o.preventDefault(),o.stopPropagation(),e.goToOption(g.Next);case P(e.orientation.value,{vertical:p.ArrowUp,horizontal:p.ArrowLeft}):return o.preventDefault(),o.stopPropagation(),e.goToOption(g.Previous);case p.Home:case p.PageUp:return o.preventDefault(),o.stopPropagation(),e.goToOption(g.First);case p.End:case p.PageDown:return o.preventDefault(),o.stopPropagation(),e.goToOption(g.Last);case p.Escape:o.preventDefault(),o.stopPropagation(),e.closeListbox(),C(()=>{var i;return(i=S(e.buttonRef))==null?void 0:i.focus({preventScroll:!0})});break;case p.Tab:o.preventDefault(),o.stopPropagation();break;default:o.key.length===1&&(e.search(o.key),d.value=setTimeout(()=>e.clearSearch(),350));break}}let b=ie(),f=x(()=>b!==null?(b.value&B.Open)===B.Open:e.listboxState.value===0);return()=>{var y,h;let o={open:e.listboxState.value===0},{id:i,...T}=t,D={"aria-activedescendant":e.activeOptionIndex.value===null||(y=e.options.value[e.activeOptionIndex.value])==null?void 0:y.id,"aria-multiselectable":e.mode.value===1?!0:void 0,"aria-labelledby":(h=S(e.buttonRef))==null?void 0:h.id,"aria-orientation":e.orientation.value,id:i,onKeydown:v,role:"listbox",tabIndex:0,ref:e.optionsRef};return j({ourProps:D,theirProps:T,slot:o,attrs:c,slots:u,features:U.RenderStrategy|U.Static,visible:f.value,name:"ListboxOptions"})}}}),Fe=E({name:"ListboxOption",props:{as:{type:[Object,String],default:"li"},value:{type:[Object,String,Number,Boolean]},disabled:{type:Boolean,default:!1},id:{type:String,default:()=>`headlessui-listbox.option-${F()}`}},setup(t,{slots:c,attrs:u,expose:L}){let e=A("ListboxOption"),d=w(null);L({el:d,$el:d});let v=x(()=>e.activeOptionIndex.value!==null?e.options.value[e.activeOptionIndex.value].id===t.id:!1),b=x(()=>P(e.mode.value,{[0]:()=>e.compare(R(e.value.value),R(t.value)),[1]:()=>R(e.value.value).some(r=>e.compare(R(r),R(t.value)))})),f=x(()=>P(e.mode.value,{[1]:()=>{var m;let r=R(e.value.value);return((m=e.options.value.find(a=>r.some(n=>e.compare(R(n),R(a.dataRef.value)))))==null?void 0:m.id)===t.id},[0]:()=>b.value})),o=Z(d),i=x(()=>({disabled:t.disabled,value:t.value,get textValue(){return o()},domRef:d}));K(()=>e.registerOption(t.id,i)),q(()=>e.unregisterOption(t.id)),K(()=>{H([e.listboxState,b],()=>{e.listboxState.value===0&&b.value&&P(e.mode.value,{[1]:()=>{f.value&&e.goToOption(g.Specific,t.id)},[0]:()=>{e.goToOption(g.Specific,t.id)}})},{immediate:!0})}),G(()=>{e.listboxState.value===0&&v.value&&e.activationTrigger.value!==0&&C(()=>{var r,m;return(m=(r=S(d))==null?void 0:r.scrollIntoView)==null?void 0:m.call(r,{block:"nearest"})})});function T(r){if(t.disabled)return r.preventDefault();e.select(t.value),e.mode.value===0&&(e.closeListbox(),C(()=>{var m;return(m=S(e.buttonRef))==null?void 0:m.focus({preventScroll:!0})}))}function D(){if(t.disabled)return e.goToOption(g.Nothing);e.goToOption(g.Specific,t.id)}let y=ee();function h(r){y.update(r)}function V(r){y.wasMoved(r)&&(t.disabled||v.value||e.goToOption(g.Specific,t.id,0))}function M(r){y.wasMoved(r)&&(t.disabled||v.value&&e.goToOption(g.Nothing))}return()=>{let{disabled:r}=t,m={active:v.value,selected:b.value,disabled:r},{id:a,value:n,disabled:l,...s}=t,O={id:a,ref:d,role:"option",tabIndex:r===!0?void 0:-1,"aria-disabled":r===!0?!0:void 0,"aria-selected":b.value,disabled:void 0,onClick:T,onFocus:D,onPointerenter:h,onMouseenter:h,onPointermove:V,onMousemove:V,onPointerleave:M,onMouseleave:M};return j({ourProps:O,theirProps:s,slot:m,attrs:u,slots:c,name:"ListboxOption"})}}});export{Ie as Listbox,je as ListboxButton,Ee as ListboxLabel,Fe as ListboxOption,Ae as ListboxOptions}; |
@@ -1,1 +0,1 @@ | ||
import{computed as y,defineComponent as T,inject as C,nextTick as h,onMounted as K,onUnmounted as N,provide as j,ref as R,watchEffect as L}from"vue";import{useId as w}from'../../hooks/use-id.js';import{useOutsideClick as B}from'../../hooks/use-outside-click.js';import{useResolveButtonType as U}from'../../hooks/use-resolve-button-type.js';import{useTextValue as $}from'../../hooks/use-text-value.js';import{useTrackedPointer as V}from'../../hooks/use-tracked-pointer.js';import{useTreeWalker as H}from'../../hooks/use-tree-walker.js';import{State as D,useOpenClosed as Q,useOpenClosedProvider as _}from'../../internal/open-closed.js';import{Keys as c}from'../../keyboard.js';import{calculateActiveIndex as q,Focus as S}from'../../utils/calculate-active-index.js';import{dom as m}from'../../utils/dom.js';import{Focus as E,FocusableMode as W,focusFrom as J,isFocusableElement as z,restoreFocusIfNecessary as k,sortByDomNode as G}from'../../utils/focus-management.js';import{match as X}from'../../utils/match.js';import{Features as F,render as P}from'../../utils/render.js';var Y=(l=>(l[l.Open=0]="Open",l[l.Closed=1]="Closed",l))(Y||{}),Z=(l=>(l[l.Pointer=0]="Pointer",l[l.Other=1]="Other",l))(Z||{});function ee(r){requestAnimationFrame(()=>requestAnimationFrame(r))}let A=Symbol("MenuContext");function O(r){let b=C(A,null);if(b===null){let l=new Error(`<${r} /> is missing a parent <Menu /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(l,O),l}return b}let Ie=T({name:"Menu",props:{as:{type:[Object,String],default:"template"}},setup(r,{slots:b,attrs:l}){let I=R(1),e=R(null),f=R(null),s=R([]),g=R(""),d=R(null),o=R(1);function t(a=i=>i){let i=d.value!==null?s.value[d.value]:null,u=G(a(s.value.slice()),v=>m(v.dataRef.domRef)),n=i?u.indexOf(i):null;return n===-1&&(n=null),{items:u,activeItemIndex:n}}let p={menuState:I,buttonRef:e,itemsRef:f,items:s,searchQuery:g,activeItemIndex:d,activationTrigger:o,closeMenu:()=>{I.value=1,d.value=null},openMenu:()=>I.value=0,goToItem(a,i,u){let n=t(),v=q(a===S.Specific?{focus:S.Specific,id:i}:{focus:a},{resolveItems:()=>n.items,resolveActiveIndex:()=>n.activeItemIndex,resolveId:M=>M.id,resolveDisabled:M=>M.dataRef.disabled});g.value="",d.value=v,o.value=u!=null?u:1,s.value=n.items},search(a){let u=g.value!==""?0:1;g.value+=a.toLowerCase();let v=(d.value!==null?s.value.slice(d.value+u).concat(s.value.slice(0,d.value+u)):s.value).find(x=>x.dataRef.textValue.startsWith(g.value)&&!x.dataRef.disabled),M=v?s.value.indexOf(v):-1;M===-1||M===d.value||(d.value=M,o.value=1)},clearSearch(){g.value=""},registerItem(a,i){let u=t(n=>[...n,{id:a,dataRef:i}]);s.value=u.items,d.value=u.activeItemIndex,o.value=1},unregisterItem(a){let i=t(u=>{let n=u.findIndex(v=>v.id===a);return n!==-1&&u.splice(n,1),u});s.value=i.items,d.value=i.activeItemIndex,o.value=1}};return B([e,f],(a,i)=>{var u;p.closeMenu(),z(i,W.Loose)||(a.preventDefault(),(u=m(e))==null||u.focus())},y(()=>I.value===0)),j(A,p),_(y(()=>X(I.value,{[0]:D.Open,[1]:D.Closed}))),()=>{let a={open:I.value===0,close:p.closeMenu};return P({ourProps:{},theirProps:r,slot:a,slots:b,attrs:l,name:"Menu"})}}}),ge=T({name:"MenuButton",props:{disabled:{type:Boolean,default:!1},as:{type:[Object,String],default:"button"},id:{type:String,default:()=>`headlessui-menu-button-${w()}`}},setup(r,{attrs:b,slots:l,expose:I}){let e=O("MenuButton");I({el:e.buttonRef,$el:e.buttonRef});function f(o){switch(o.key){case c.Space:case c.Enter:case c.ArrowDown:o.preventDefault(),o.stopPropagation(),e.openMenu(),h(()=>{var t;(t=m(e.itemsRef))==null||t.focus({preventScroll:!0}),e.goToItem(S.First)});break;case c.ArrowUp:o.preventDefault(),o.stopPropagation(),e.openMenu(),h(()=>{var t;(t=m(e.itemsRef))==null||t.focus({preventScroll:!0}),e.goToItem(S.Last)});break}}function s(o){switch(o.key){case c.Space:o.preventDefault();break}}function g(o){r.disabled||(e.menuState.value===0?(e.closeMenu(),h(()=>{var t;return(t=m(e.buttonRef))==null?void 0:t.focus({preventScroll:!0})})):(o.preventDefault(),e.openMenu(),ee(()=>{var t;return(t=m(e.itemsRef))==null?void 0:t.focus({preventScroll:!0})})))}let d=U(y(()=>({as:r.as,type:b.type})),e.buttonRef);return()=>{var i;let o={open:e.menuState.value===0},{id:t,...p}=r,a={ref:e.buttonRef,id:t,type:d.value,"aria-haspopup":"menu","aria-controls":(i=m(e.itemsRef))==null?void 0:i.id,"aria-expanded":e.menuState.value===0,onKeydown:f,onKeyup:s,onClick:g};return P({ourProps:a,theirProps:p,slot:o,attrs:b,slots:l,name:"MenuButton"})}}}),Se=T({name:"MenuItems",props:{as:{type:[Object,String],default:"div"},static:{type:Boolean,default:!1},unmount:{type:Boolean,default:!0},id:{type:String,default:()=>`headlessui-menu-items-${w()}`}},setup(r,{attrs:b,slots:l,expose:I}){let e=O("MenuItems"),f=R(null);I({el:e.itemsRef,$el:e.itemsRef}),H({container:y(()=>m(e.itemsRef)),enabled:y(()=>e.menuState.value===0),accept(t){return t.getAttribute("role")==="menuitem"?NodeFilter.FILTER_REJECT:t.hasAttribute("role")?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT},walk(t){t.setAttribute("role","none")}});function s(t){var p;switch(f.value&&clearTimeout(f.value),t.key){case c.Space:if(e.searchQuery.value!=="")return t.preventDefault(),t.stopPropagation(),e.search(t.key);case c.Enter:if(t.preventDefault(),t.stopPropagation(),e.activeItemIndex.value!==null){let i=e.items.value[e.activeItemIndex.value];(p=m(i.dataRef.domRef))==null||p.click()}e.closeMenu(),k(m(e.buttonRef));break;case c.ArrowDown:return t.preventDefault(),t.stopPropagation(),e.goToItem(S.Next);case c.ArrowUp:return t.preventDefault(),t.stopPropagation(),e.goToItem(S.Previous);case c.Home:case c.PageUp:return t.preventDefault(),t.stopPropagation(),e.goToItem(S.First);case c.End:case c.PageDown:return t.preventDefault(),t.stopPropagation(),e.goToItem(S.Last);case c.Escape:t.preventDefault(),t.stopPropagation(),e.closeMenu(),h(()=>{var a;return(a=m(e.buttonRef))==null?void 0:a.focus({preventScroll:!0})});break;case c.Tab:t.preventDefault(),t.stopPropagation(),e.closeMenu(),h(()=>J(m(e.buttonRef),t.shiftKey?E.Previous:E.Next));break;default:t.key.length===1&&(e.search(t.key),f.value=setTimeout(()=>e.clearSearch(),350));break}}function g(t){switch(t.key){case c.Space:t.preventDefault();break}}let d=Q(),o=y(()=>d!==null?(d.value&D.Open)===D.Open:e.menuState.value===0);return()=>{var u,n;let t={open:e.menuState.value===0},{id:p,...a}=r,i={"aria-activedescendant":e.activeItemIndex.value===null||(u=e.items.value[e.activeItemIndex.value])==null?void 0:u.id,"aria-labelledby":(n=m(e.buttonRef))==null?void 0:n.id,id:p,onKeydown:s,onKeyup:g,role:"menu",tabIndex:0,ref:e.itemsRef};return P({ourProps:i,theirProps:a,slot:t,attrs:b,slots:l,features:F.RenderStrategy|F.Static,visible:o.value,name:"MenuItems"})}}}),be=T({name:"MenuItem",inheritAttrs:!1,props:{as:{type:[Object,String],default:"template"},disabled:{type:Boolean,default:!1},id:{type:String,default:()=>`headlessui-menu-item-${w()}`}},setup(r,{slots:b,attrs:l,expose:I}){let e=O("MenuItem"),f=R(null);I({el:f,$el:f});let s=y(()=>e.activeItemIndex.value!==null?e.items.value[e.activeItemIndex.value].id===r.id:!1),g=$(f),d=y(()=>({disabled:r.disabled,get textValue(){return g()},domRef:f}));K(()=>e.registerItem(r.id,d)),N(()=>e.unregisterItem(r.id)),L(()=>{e.menuState.value===0&&s.value&&e.activationTrigger.value!==0&&h(()=>{var n,v;return(v=(n=m(f))==null?void 0:n.scrollIntoView)==null?void 0:v.call(n,{block:"nearest"})})});function o(n){if(r.disabled)return n.preventDefault();e.closeMenu(),k(m(e.buttonRef))}function t(){if(r.disabled)return e.goToItem(S.Nothing);e.goToItem(S.Specific,r.id)}let p=V();function a(n){p.update(n)}function i(n){p.wasMoved(n)&&(r.disabled||s.value||e.goToItem(S.Specific,r.id,0))}function u(n){p.wasMoved(n)&&(r.disabled||s.value&&e.goToItem(S.Nothing))}return()=>{let{disabled:n}=r,v={active:s.value,disabled:n,close:e.closeMenu},{id:M,...x}=r;return P({ourProps:{id:M,ref:f,role:"menuitem",tabIndex:n===!0?void 0:-1,"aria-disabled":n===!0?!0:void 0,disabled:void 0,onClick:o,onFocus:t,onPointerenter:a,onMouseenter:a,onPointermove:i,onMousemove:i,onPointerleave:u,onMouseleave:u},theirProps:{...l,...x},slot:v,attrs:l,slots:b,name:"MenuItem"})}}});export{Ie as Menu,ge as MenuButton,be as MenuItem,Se as MenuItems}; | ||
import{computed as y,defineComponent as T,inject as C,nextTick as h,onMounted as K,onUnmounted as N,provide as j,ref as R,watchEffect as L}from"vue";import{useId as w}from'../../hooks/use-id.js';import{useOutsideClick as B}from'../../hooks/use-outside-click.js';import{useResolveButtonType as U}from'../../hooks/use-resolve-button-type.js';import{useTextValue as $}from'../../hooks/use-text-value.js';import{useTrackedPointer as V}from'../../hooks/use-tracked-pointer.js';import{useTreeWalker as H}from'../../hooks/use-tree-walker.js';import{State as D,useOpenClosed as Q,useOpenClosedProvider as _}from'../../internal/open-closed.js';import{Keys as c}from'../../keyboard.js';import{Focus as S,calculateActiveIndex as q}from'../../utils/calculate-active-index.js';import{dom as p}from'../../utils/dom.js';import{Focus as E,FocusableMode as W,focusFrom as J,isFocusableElement as z,restoreFocusIfNecessary as k,sortByDomNode as G}from'../../utils/focus-management.js';import{match as X}from'../../utils/match.js';import{Features as F,render as P}from'../../utils/render.js';var Y=(l=>(l[l.Open=0]="Open",l[l.Closed=1]="Closed",l))(Y||{}),Z=(l=>(l[l.Pointer=0]="Pointer",l[l.Other=1]="Other",l))(Z||{});function ee(i){requestAnimationFrame(()=>requestAnimationFrame(i))}let A=Symbol("MenuContext");function O(i){let M=C(A,null);if(M===null){let l=new Error(`<${i} /> is missing a parent <Menu /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(l,O),l}return M}let Ie=T({name:"Menu",props:{as:{type:[Object,String],default:"template"}},setup(i,{slots:M,attrs:l}){let I=R(1),e=R(null),f=R(null),s=R([]),g=R(""),d=R(null),o=R(1);function t(a=r=>r){let r=d.value!==null?s.value[d.value]:null,u=G(a(s.value.slice()),m=>p(m.dataRef.domRef)),n=r?u.indexOf(r):null;return n===-1&&(n=null),{items:u,activeItemIndex:n}}let v={menuState:I,buttonRef:e,itemsRef:f,items:s,searchQuery:g,activeItemIndex:d,activationTrigger:o,closeMenu:()=>{I.value=1,d.value=null},openMenu:()=>I.value=0,goToItem(a,r,u){let n=t(),m=q(a===S.Specific?{focus:S.Specific,id:r}:{focus:a},{resolveItems:()=>n.items,resolveActiveIndex:()=>n.activeItemIndex,resolveId:b=>b.id,resolveDisabled:b=>b.dataRef.disabled});g.value="",d.value=m,o.value=u!=null?u:1,s.value=n.items},search(a){let u=g.value!==""?0:1;g.value+=a.toLowerCase();let m=(d.value!==null?s.value.slice(d.value+u).concat(s.value.slice(0,d.value+u)):s.value).find(x=>x.dataRef.textValue.startsWith(g.value)&&!x.dataRef.disabled),b=m?s.value.indexOf(m):-1;b===-1||b===d.value||(d.value=b,o.value=1)},clearSearch(){g.value=""},registerItem(a,r){let u=t(n=>[...n,{id:a,dataRef:r}]);s.value=u.items,d.value=u.activeItemIndex,o.value=1},unregisterItem(a){let r=t(u=>{let n=u.findIndex(m=>m.id===a);return n!==-1&&u.splice(n,1),u});s.value=r.items,d.value=r.activeItemIndex,o.value=1}};return B([e,f],(a,r)=>{var u;v.closeMenu(),z(r,W.Loose)||(a.preventDefault(),(u=p(e))==null||u.focus())},y(()=>I.value===0)),j(A,v),_(y(()=>X(I.value,{[0]:D.Open,[1]:D.Closed}))),()=>{let a={open:I.value===0,close:v.closeMenu};return P({ourProps:{},theirProps:i,slot:a,slots:M,attrs:l,name:"Menu"})}}}),ge=T({name:"MenuButton",props:{disabled:{type:Boolean,default:!1},as:{type:[Object,String],default:"button"},id:{type:String,default:()=>`headlessui-menu-button-${w()}`}},setup(i,{attrs:M,slots:l,expose:I}){let e=O("MenuButton");I({el:e.buttonRef,$el:e.buttonRef});function f(o){switch(o.key){case c.Space:case c.Enter:case c.ArrowDown:o.preventDefault(),o.stopPropagation(),e.openMenu(),h(()=>{var t;(t=p(e.itemsRef))==null||t.focus({preventScroll:!0}),e.goToItem(S.First)});break;case c.ArrowUp:o.preventDefault(),o.stopPropagation(),e.openMenu(),h(()=>{var t;(t=p(e.itemsRef))==null||t.focus({preventScroll:!0}),e.goToItem(S.Last)});break}}function s(o){switch(o.key){case c.Space:o.preventDefault();break}}function g(o){i.disabled||(e.menuState.value===0?(e.closeMenu(),h(()=>{var t;return(t=p(e.buttonRef))==null?void 0:t.focus({preventScroll:!0})})):(o.preventDefault(),e.openMenu(),ee(()=>{var t;return(t=p(e.itemsRef))==null?void 0:t.focus({preventScroll:!0})})))}let d=U(y(()=>({as:i.as,type:M.type})),e.buttonRef);return()=>{var r;let o={open:e.menuState.value===0},{id:t,...v}=i,a={ref:e.buttonRef,id:t,type:d.value,"aria-haspopup":"menu","aria-controls":(r=p(e.itemsRef))==null?void 0:r.id,"aria-expanded":e.menuState.value===0,onKeydown:f,onKeyup:s,onClick:g};return P({ourProps:a,theirProps:v,slot:o,attrs:M,slots:l,name:"MenuButton"})}}}),Se=T({name:"MenuItems",props:{as:{type:[Object,String],default:"div"},static:{type:Boolean,default:!1},unmount:{type:Boolean,default:!0},id:{type:String,default:()=>`headlessui-menu-items-${w()}`}},setup(i,{attrs:M,slots:l,expose:I}){let e=O("MenuItems"),f=R(null);I({el:e.itemsRef,$el:e.itemsRef}),H({container:y(()=>p(e.itemsRef)),enabled:y(()=>e.menuState.value===0),accept(t){return t.getAttribute("role")==="menuitem"?NodeFilter.FILTER_REJECT:t.hasAttribute("role")?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT},walk(t){t.setAttribute("role","none")}});function s(t){var v;switch(f.value&&clearTimeout(f.value),t.key){case c.Space:if(e.searchQuery.value!=="")return t.preventDefault(),t.stopPropagation(),e.search(t.key);case c.Enter:if(t.preventDefault(),t.stopPropagation(),e.activeItemIndex.value!==null){let r=e.items.value[e.activeItemIndex.value];(v=p(r.dataRef.domRef))==null||v.click()}e.closeMenu(),k(p(e.buttonRef));break;case c.ArrowDown:return t.preventDefault(),t.stopPropagation(),e.goToItem(S.Next);case c.ArrowUp:return t.preventDefault(),t.stopPropagation(),e.goToItem(S.Previous);case c.Home:case c.PageUp:return t.preventDefault(),t.stopPropagation(),e.goToItem(S.First);case c.End:case c.PageDown:return t.preventDefault(),t.stopPropagation(),e.goToItem(S.Last);case c.Escape:t.preventDefault(),t.stopPropagation(),e.closeMenu(),h(()=>{var a;return(a=p(e.buttonRef))==null?void 0:a.focus({preventScroll:!0})});break;case c.Tab:t.preventDefault(),t.stopPropagation(),e.closeMenu(),h(()=>J(p(e.buttonRef),t.shiftKey?E.Previous:E.Next));break;default:t.key.length===1&&(e.search(t.key),f.value=setTimeout(()=>e.clearSearch(),350));break}}function g(t){switch(t.key){case c.Space:t.preventDefault();break}}let d=Q(),o=y(()=>d!==null?(d.value&D.Open)===D.Open:e.menuState.value===0);return()=>{var u,n;let t={open:e.menuState.value===0},{id:v,...a}=i,r={"aria-activedescendant":e.activeItemIndex.value===null||(u=e.items.value[e.activeItemIndex.value])==null?void 0:u.id,"aria-labelledby":(n=p(e.buttonRef))==null?void 0:n.id,id:v,onKeydown:s,onKeyup:g,role:"menu",tabIndex:0,ref:e.itemsRef};return P({ourProps:r,theirProps:a,slot:t,attrs:M,slots:l,features:F.RenderStrategy|F.Static,visible:o.value,name:"MenuItems"})}}}),Me=T({name:"MenuItem",inheritAttrs:!1,props:{as:{type:[Object,String],default:"template"},disabled:{type:Boolean,default:!1},id:{type:String,default:()=>`headlessui-menu-item-${w()}`}},setup(i,{slots:M,attrs:l,expose:I}){let e=O("MenuItem"),f=R(null);I({el:f,$el:f});let s=y(()=>e.activeItemIndex.value!==null?e.items.value[e.activeItemIndex.value].id===i.id:!1),g=$(f),d=y(()=>({disabled:i.disabled,get textValue(){return g()},domRef:f}));K(()=>e.registerItem(i.id,d)),N(()=>e.unregisterItem(i.id)),L(()=>{e.menuState.value===0&&s.value&&e.activationTrigger.value!==0&&h(()=>{var n,m;return(m=(n=p(f))==null?void 0:n.scrollIntoView)==null?void 0:m.call(n,{block:"nearest"})})});function o(n){if(i.disabled)return n.preventDefault();e.closeMenu(),k(p(e.buttonRef))}function t(){if(i.disabled)return e.goToItem(S.Nothing);e.goToItem(S.Specific,i.id)}let v=V();function a(n){v.update(n)}function r(n){v.wasMoved(n)&&(i.disabled||s.value||e.goToItem(S.Specific,i.id,0))}function u(n){v.wasMoved(n)&&(i.disabled||s.value&&e.goToItem(S.Nothing))}return()=>{let{id:n,disabled:m,...b}=i,x={active:s.value,disabled:m,close:e.closeMenu};return P({ourProps:{id:n,ref:f,role:"menuitem",tabIndex:m===!0?void 0:-1,"aria-disabled":m===!0?!0:void 0,onClick:o,onFocus:t,onPointerenter:a,onMouseenter:a,onPointermove:r,onMousemove:r,onPointerleave:u,onMouseleave:u},theirProps:{...l,...b},slot:x,attrs:l,slots:M,name:"MenuItem"})}}});export{Ie as Menu,ge as MenuButton,Me as MenuItem,Se as MenuItems}; |
@@ -131,4 +131,4 @@ export declare let Popover: import("vue").DefineComponent<{ | ||
}>>, { | ||
focus: boolean; | ||
id: string; | ||
focus: boolean; | ||
as: string | Record<string, any>; | ||
@@ -135,0 +135,0 @@ unmount: boolean; |
@@ -1,1 +0,1 @@ | ||
import{computed as T,defineComponent as K,Fragment as j,h as R,inject as _,onMounted as ee,onUnmounted as te,provide as U,ref as F,shallowRef as ie,watchEffect as q}from"vue";import{useNestedPortals as se}from'../../components/portal/portal.js';import{useEventListener as pe}from'../../hooks/use-event-listener.js';import{useId as L}from'../../hooks/use-id.js';import{useOutsideClick as fe}from'../../hooks/use-outside-click.js';import{useResolveButtonType as ve}from'../../hooks/use-resolve-button-type.js';import{useMainTreeNode as ce,useRootContainers as de}from'../../hooks/use-root-containers.js';import{Direction as w,useTabDirection as oe}from'../../hooks/use-tab-direction.js';import{Features as z,Hidden as J}from'../../internal/hidden.js';import{State as x,useOpenClosed as ne,useOpenClosedProvider as Pe}from'../../internal/open-closed.js';import{Keys as D}from'../../keyboard.js';import{dom as r}from'../../utils/dom.js';import{Focus as C,FocusableMode as me,focusIn as k,FocusResult as Q,getFocusableElements as X,isFocusableElement as be}from'../../utils/focus-management.js';import{match as H}from'../../utils/match.js';import'../../utils/micro-task.js';import{getOwnerDocument as A}from'../../utils/owner.js';import{Features as W,render as G}from'../../utils/render.js';var Se=(p=>(p[p.Open=0]="Open",p[p.Closed=1]="Closed",p))(Se||{});let re=Symbol("PopoverContext");function V(P){let b=_(re,null);if(b===null){let p=new Error(`<${P} /> is missing a parent <${ye.name} /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(p,V),p}return b}let le=Symbol("PopoverGroupContext");function ae(){return _(le,null)}let ue=Symbol("PopoverPanelContext");function ge(){return _(ue,null)}let ye=K({name:"Popover",inheritAttrs:!1,props:{as:{type:[Object,String],default:"div"}},setup(P,{slots:b,attrs:p,expose:h}){var v;let t=F(null);h({el:t,$el:t});let e=F(1),c=F(null),d=F(null),O=F(null),f=F(null),y=T(()=>A(t)),M=T(()=>{var Y,Z;if(!r(c)||!r(f))return!1;for(let B of document.querySelectorAll("body > *"))if(Number(B==null?void 0:B.contains(r(c)))^Number(B==null?void 0:B.contains(r(f))))return!0;let o=X(),a=o.indexOf(r(c)),g=(a+o.length-1)%o.length,E=(a+1)%o.length,N=o[g],$=o[E];return!((Y=r(f))!=null&&Y.contains(N))&&!((Z=r(f))!=null&&Z.contains($))}),l={popoverState:e,buttonId:F(null),panelId:F(null),panel:f,button:c,isPortalled:M,beforePanelSentinel:d,afterPanelSentinel:O,togglePopover(){e.value=H(e.value,{[0]:1,[1]:0})},closePopover(){e.value!==1&&(e.value=1)},close(o){l.closePopover();let a=(()=>o?o instanceof HTMLElement?o:o.value instanceof HTMLElement?r(o):r(l.button):r(l.button))();a==null||a.focus()}};U(re,l),Pe(T(()=>H(e.value,{[0]:x.Open,[1]:x.Closed})));let m={buttonId:l.buttonId,panelId:l.panelId,close(){l.closePopover()}},S=ae(),I=S==null?void 0:S.registerPopover,[s,u]=se(),i=de({mainTreeNodeRef:S==null?void 0:S.mainTreeNodeRef,portals:s,defaultContainers:[c,f]});function n(){var o,a,g,E;return(E=S==null?void 0:S.isFocusWithinPopoverGroup())!=null?E:((o=y.value)==null?void 0:o.activeElement)&&(((a=r(c))==null?void 0:a.contains(y.value.activeElement))||((g=r(f))==null?void 0:g.contains(y.value.activeElement)))}return q(()=>I==null?void 0:I(m)),pe((v=y.value)==null?void 0:v.defaultView,"focus",o=>{var a,g;o.target!==window&&o.target instanceof HTMLElement&&e.value===0&&(n()||c&&f&&(i.contains(o.target)||(a=r(l.beforePanelSentinel))!=null&&a.contains(o.target)||(g=r(l.afterPanelSentinel))!=null&&g.contains(o.target)||l.closePopover()))},!0),fe(i.resolveContainers,(o,a)=>{var g;l.closePopover(),be(a,me.Loose)||(o.preventDefault(),(g=r(c))==null||g.focus())},T(()=>e.value===0)),()=>{let o={open:e.value===0,close:l.close};return R(j,[R(u,{},()=>G({theirProps:{...P,...p},ourProps:{ref:t},slot:o,slots:b,attrs:p,name:"Popover"})),R(i.MainTreeNode)])}}}),Ge=K({name:"PopoverButton",props:{as:{type:[Object,String],default:"button"},disabled:{type:[Boolean],default:!1},id:{type:String,default:()=>`headlessui-popover-button-${L()}`}},inheritAttrs:!1,setup(P,{attrs:b,slots:p,expose:h}){let t=V("PopoverButton"),e=T(()=>A(t.button));h({el:t.button,$el:t.button}),ee(()=>{t.buttonId.value=P.id}),te(()=>{t.buttonId.value=null});let c=ae(),d=c==null?void 0:c.closeOthers,O=ge(),f=T(()=>O===null?!1:O.value===t.panelId.value),y=F(null),M=`headlessui-focus-sentinel-${L()}`;f.value||q(()=>{t.button.value=r(y)});let l=ve(T(()=>({as:P.as,type:b.type})),y);function m(n){var v,o,a,g,E;if(f.value){if(t.popoverState.value===1)return;switch(n.key){case D.Space:case D.Enter:n.preventDefault(),(o=(v=n.target).click)==null||o.call(v),t.closePopover(),(a=r(t.button))==null||a.focus();break}}else switch(n.key){case D.Space:case D.Enter:n.preventDefault(),n.stopPropagation(),t.popoverState.value===1&&(d==null||d(t.buttonId.value)),t.togglePopover();break;case D.Escape:if(t.popoverState.value!==0)return d==null?void 0:d(t.buttonId.value);if(!r(t.button)||(g=e.value)!=null&&g.activeElement&&!((E=r(t.button))!=null&&E.contains(e.value.activeElement)))return;n.preventDefault(),n.stopPropagation(),t.closePopover();break}}function S(n){f.value||n.key===D.Space&&n.preventDefault()}function I(n){var v,o;P.disabled||(f.value?(t.closePopover(),(v=r(t.button))==null||v.focus()):(n.preventDefault(),n.stopPropagation(),t.popoverState.value===1&&(d==null||d(t.buttonId.value)),t.togglePopover(),(o=r(t.button))==null||o.focus()))}function s(n){n.preventDefault(),n.stopPropagation()}let u=oe();function i(){let n=r(t.panel);if(!n)return;function v(){H(u.value,{[w.Forwards]:()=>k(n,C.First),[w.Backwards]:()=>k(n,C.Last)})===Q.Error&&k(X().filter(a=>a.dataset.headlessuiFocusGuard!=="true"),H(u.value,{[w.Forwards]:C.Next,[w.Backwards]:C.Previous}),{relativeTo:r(t.button)})}v()}return()=>{let n=t.popoverState.value===0,v={open:n},{id:o,...a}=P,g=f.value?{ref:y,type:l.value,onKeydown:m,onClick:I}:{ref:y,id:o,type:l.value,"aria-expanded":t.popoverState.value===0,"aria-controls":r(t.panel)?t.panelId.value:void 0,disabled:P.disabled?!0:void 0,onKeydown:m,onKeyup:S,onClick:I,onMousedown:s};return R(j,[G({ourProps:g,theirProps:{...b,...a},slot:v,attrs:b,slots:p,name:"PopoverButton"}),n&&!f.value&&t.isPortalled.value&&R(J,{id:M,features:z.Focusable,"data-headlessui-focus-guard":!0,as:"button",type:"button",onFocus:i})])}}}),$e=K({name:"PopoverOverlay",props:{as:{type:[Object,String],default:"div"},static:{type:Boolean,default:!1},unmount:{type:Boolean,default:!0}},setup(P,{attrs:b,slots:p}){let h=V("PopoverOverlay"),t=`headlessui-popover-overlay-${L()}`,e=ne(),c=T(()=>e!==null?(e.value&x.Open)===x.Open:h.popoverState.value===0);function d(){h.closePopover()}return()=>{let O={open:h.popoverState.value===0};return G({ourProps:{id:t,"aria-hidden":!0,onClick:d},theirProps:P,slot:O,attrs:b,slots:p,features:W.RenderStrategy|W.Static,visible:c.value,name:"PopoverOverlay"})}}}),je=K({name:"PopoverPanel",props:{as:{type:[Object,String],default:"div"},static:{type:Boolean,default:!1},unmount:{type:Boolean,default:!0},focus:{type:Boolean,default:!1},id:{type:String,default:()=>`headlessui-popover-panel-${L()}`}},inheritAttrs:!1,setup(P,{attrs:b,slots:p,expose:h}){let{focus:t}=P,e=V("PopoverPanel"),c=T(()=>A(e.panel)),d=`headlessui-focus-sentinel-before-${L()}`,O=`headlessui-focus-sentinel-after-${L()}`;h({el:e.panel,$el:e.panel}),ee(()=>{e.panelId.value=P.id}),te(()=>{e.panelId.value=null}),U(ue,e.panelId),q(()=>{var u,i;if(!t||e.popoverState.value!==0||!e.panel)return;let s=(u=c.value)==null?void 0:u.activeElement;(i=r(e.panel))!=null&&i.contains(s)||k(r(e.panel),C.First)});let f=ne(),y=T(()=>f!==null?(f.value&x.Open)===x.Open:e.popoverState.value===0);function M(s){var u,i;switch(s.key){case D.Escape:if(e.popoverState.value!==0||!r(e.panel)||c.value&&!((u=r(e.panel))!=null&&u.contains(c.value.activeElement)))return;s.preventDefault(),s.stopPropagation(),e.closePopover(),(i=r(e.button))==null||i.focus();break}}function l(s){var i,n,v,o,a;let u=s.relatedTarget;u&&r(e.panel)&&((i=r(e.panel))!=null&&i.contains(u)||(e.closePopover(),((v=(n=r(e.beforePanelSentinel))==null?void 0:n.contains)!=null&&v.call(n,u)||(a=(o=r(e.afterPanelSentinel))==null?void 0:o.contains)!=null&&a.call(o,u))&&u.focus({preventScroll:!0})))}let m=oe();function S(){let s=r(e.panel);if(!s)return;function u(){H(m.value,{[w.Forwards]:()=>{var n;k(s,C.First)===Q.Error&&((n=r(e.afterPanelSentinel))==null||n.focus())},[w.Backwards]:()=>{var i;(i=r(e.button))==null||i.focus({preventScroll:!0})}})}u()}function I(){let s=r(e.panel);if(!s)return;function u(){H(m.value,{[w.Forwards]:()=>{let i=r(e.button),n=r(e.panel);if(!i)return;let v=X(),o=v.indexOf(i),a=v.slice(0,o+1),E=[...v.slice(o+1),...a];for(let N of E.slice())if(N.dataset.headlessuiFocusGuard==="true"||n!=null&&n.contains(N)){let $=E.indexOf(N);$!==-1&&E.splice($,1)}k(E,C.First,{sorted:!1})},[w.Backwards]:()=>{var n;k(s,C.Previous)===Q.Error&&((n=r(e.button))==null||n.focus())}})}u()}return()=>{let s={open:e.popoverState.value===0,close:e.close},{id:u,focus:i,...n}=P,v={ref:e.panel,id:u,onKeydown:M,onFocusout:t&&e.popoverState.value===0?l:void 0,tabIndex:-1};return G({ourProps:v,theirProps:{...b,...n},attrs:b,slot:s,slots:{...p,default:(...o)=>{var a;return[R(j,[y.value&&e.isPortalled.value&&R(J,{id:d,ref:e.beforePanelSentinel,features:z.Focusable,"data-headlessui-focus-guard":!0,as:"button",type:"button",onFocus:S}),(a=p.default)==null?void 0:a.call(p,...o),y.value&&e.isPortalled.value&&R(J,{id:O,ref:e.afterPanelSentinel,features:z.Focusable,"data-headlessui-focus-guard":!0,as:"button",type:"button",onFocus:I})])]}},features:W.RenderStrategy|W.Static,visible:y.value,name:"PopoverPanel"})}}}),Ae=K({name:"PopoverGroup",inheritAttrs:!1,props:{as:{type:[Object,String],default:"div"}},setup(P,{attrs:b,slots:p,expose:h}){let t=F(null),e=ie([]),c=T(()=>A(t)),d=ce();h({el:t,$el:t});function O(l){let m=e.value.indexOf(l);m!==-1&&e.value.splice(m,1)}function f(l){return e.value.push(l),()=>{O(l)}}function y(){var S;let l=c.value;if(!l)return!1;let m=l.activeElement;return(S=r(t))!=null&&S.contains(m)?!0:e.value.some(I=>{var s,u;return((s=l.getElementById(I.buttonId.value))==null?void 0:s.contains(m))||((u=l.getElementById(I.panelId.value))==null?void 0:u.contains(m))})}function M(l){for(let m of e.value)m.buttonId.value!==l&&m.close()}return U(le,{registerPopover:f,unregisterPopover:O,isFocusWithinPopoverGroup:y,closeOthers:M,mainTreeNodeRef:d.mainTreeNodeRef}),()=>R(j,[G({ourProps:{ref:t},theirProps:{...P,...b},slot:{},attrs:b,slots:p,name:"PopoverGroup"}),R(d.MainTreeNode)])}});export{ye as Popover,Ge as PopoverButton,Ae as PopoverGroup,$e as PopoverOverlay,je as PopoverPanel}; | ||
import{Fragment as j,computed as T,defineComponent as K,h as R,inject as _,onMounted as ee,onUnmounted as te,provide as U,ref as F,shallowRef as ie,watchEffect as q}from"vue";import{useNestedPortals as se}from'../../components/portal/portal.js';import{useEventListener as pe}from'../../hooks/use-event-listener.js';import{useId as L}from'../../hooks/use-id.js';import{useOutsideClick as fe}from'../../hooks/use-outside-click.js';import{useResolveButtonType as ve}from'../../hooks/use-resolve-button-type.js';import{useMainTreeNode as ce,useRootContainers as de}from'../../hooks/use-root-containers.js';import{Direction as w,useTabDirection as oe}from'../../hooks/use-tab-direction.js';import{Hidden as z,Features as J}from'../../internal/hidden.js';import{State as x,useOpenClosed as ne,useOpenClosedProvider as Pe}from'../../internal/open-closed.js';import{Keys as D}from'../../keyboard.js';import{dom as r}from'../../utils/dom.js';import{Focus as C,FocusResult as Q,FocusableMode as me,focusIn as B,getFocusableElements as X,isFocusableElement as be}from'../../utils/focus-management.js';import{match as H}from'../../utils/match.js';import'../../utils/micro-task.js';import{getOwnerDocument as A}from'../../utils/owner.js';import{Features as W,render as G}from'../../utils/render.js';var Se=(p=>(p[p.Open=0]="Open",p[p.Closed=1]="Closed",p))(Se||{});let re=Symbol("PopoverContext");function V(P){let b=_(re,null);if(b===null){let p=new Error(`<${P} /> is missing a parent <${ye.name} /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(p,V),p}return b}let le=Symbol("PopoverGroupContext");function ae(){return _(le,null)}let ue=Symbol("PopoverPanelContext");function ge(){return _(ue,null)}let ye=K({name:"Popover",inheritAttrs:!1,props:{as:{type:[Object,String],default:"div"}},setup(P,{slots:b,attrs:p,expose:h}){var v;let t=F(null);h({el:t,$el:t});let e=F(1),c=F(null),d=F(null),O=F(null),f=F(null),y=T(()=>A(t)),M=T(()=>{var Y,Z;if(!r(c)||!r(f))return!1;for(let k of document.querySelectorAll("body > *"))if(Number(k==null?void 0:k.contains(r(c)))^Number(k==null?void 0:k.contains(r(f))))return!0;let o=X(),a=o.indexOf(r(c)),g=(a+o.length-1)%o.length,E=(a+1)%o.length,N=o[g],$=o[E];return!((Y=r(f))!=null&&Y.contains(N))&&!((Z=r(f))!=null&&Z.contains($))}),l={popoverState:e,buttonId:F(null),panelId:F(null),panel:f,button:c,isPortalled:M,beforePanelSentinel:d,afterPanelSentinel:O,togglePopover(){e.value=H(e.value,{[0]:1,[1]:0})},closePopover(){e.value!==1&&(e.value=1)},close(o){l.closePopover();let a=(()=>o?o instanceof HTMLElement?o:o.value instanceof HTMLElement?r(o):r(l.button):r(l.button))();a==null||a.focus()}};U(re,l),Pe(T(()=>H(e.value,{[0]:x.Open,[1]:x.Closed})));let m={buttonId:l.buttonId,panelId:l.panelId,close(){l.closePopover()}},S=ae(),I=S==null?void 0:S.registerPopover,[s,u]=se(),i=de({mainTreeNodeRef:S==null?void 0:S.mainTreeNodeRef,portals:s,defaultContainers:[c,f]});function n(){var o,a,g,E;return(E=S==null?void 0:S.isFocusWithinPopoverGroup())!=null?E:((o=y.value)==null?void 0:o.activeElement)&&(((a=r(c))==null?void 0:a.contains(y.value.activeElement))||((g=r(f))==null?void 0:g.contains(y.value.activeElement)))}return q(()=>I==null?void 0:I(m)),pe((v=y.value)==null?void 0:v.defaultView,"focus",o=>{var a,g;o.target!==window&&o.target instanceof HTMLElement&&e.value===0&&(n()||c&&f&&(i.contains(o.target)||(a=r(l.beforePanelSentinel))!=null&&a.contains(o.target)||(g=r(l.afterPanelSentinel))!=null&&g.contains(o.target)||l.closePopover()))},!0),fe(i.resolveContainers,(o,a)=>{var g;l.closePopover(),be(a,me.Loose)||(o.preventDefault(),(g=r(c))==null||g.focus())},T(()=>e.value===0)),()=>{let o={open:e.value===0,close:l.close};return R(j,[R(u,{},()=>G({theirProps:{...P,...p},ourProps:{ref:t},slot:o,slots:b,attrs:p,name:"Popover"})),R(i.MainTreeNode)])}}}),Ge=K({name:"PopoverButton",props:{as:{type:[Object,String],default:"button"},disabled:{type:[Boolean],default:!1},id:{type:String,default:()=>`headlessui-popover-button-${L()}`}},inheritAttrs:!1,setup(P,{attrs:b,slots:p,expose:h}){let t=V("PopoverButton"),e=T(()=>A(t.button));h({el:t.button,$el:t.button}),ee(()=>{t.buttonId.value=P.id}),te(()=>{t.buttonId.value=null});let c=ae(),d=c==null?void 0:c.closeOthers,O=ge(),f=T(()=>O===null?!1:O.value===t.panelId.value),y=F(null),M=`headlessui-focus-sentinel-${L()}`;f.value||q(()=>{t.button.value=r(y)});let l=ve(T(()=>({as:P.as,type:b.type})),y);function m(n){var v,o,a,g,E;if(f.value){if(t.popoverState.value===1)return;switch(n.key){case D.Space:case D.Enter:n.preventDefault(),(o=(v=n.target).click)==null||o.call(v),t.closePopover(),(a=r(t.button))==null||a.focus();break}}else switch(n.key){case D.Space:case D.Enter:n.preventDefault(),n.stopPropagation(),t.popoverState.value===1&&(d==null||d(t.buttonId.value)),t.togglePopover();break;case D.Escape:if(t.popoverState.value!==0)return d==null?void 0:d(t.buttonId.value);if(!r(t.button)||(g=e.value)!=null&&g.activeElement&&!((E=r(t.button))!=null&&E.contains(e.value.activeElement)))return;n.preventDefault(),n.stopPropagation(),t.closePopover();break}}function S(n){f.value||n.key===D.Space&&n.preventDefault()}function I(n){var v,o;P.disabled||(f.value?(t.closePopover(),(v=r(t.button))==null||v.focus()):(n.preventDefault(),n.stopPropagation(),t.popoverState.value===1&&(d==null||d(t.buttonId.value)),t.togglePopover(),(o=r(t.button))==null||o.focus()))}function s(n){n.preventDefault(),n.stopPropagation()}let u=oe();function i(){let n=r(t.panel);if(!n)return;function v(){H(u.value,{[w.Forwards]:()=>B(n,C.First),[w.Backwards]:()=>B(n,C.Last)})===Q.Error&&B(X().filter(a=>a.dataset.headlessuiFocusGuard!=="true"),H(u.value,{[w.Forwards]:C.Next,[w.Backwards]:C.Previous}),{relativeTo:r(t.button)})}v()}return()=>{let n=t.popoverState.value===0,v={open:n},{id:o,...a}=P,g=f.value?{ref:y,type:l.value,onKeydown:m,onClick:I}:{ref:y,id:o,type:l.value,"aria-expanded":t.popoverState.value===0,"aria-controls":r(t.panel)?t.panelId.value:void 0,disabled:P.disabled?!0:void 0,onKeydown:m,onKeyup:S,onClick:I,onMousedown:s};return R(j,[G({ourProps:g,theirProps:{...b,...a},slot:v,attrs:b,slots:p,name:"PopoverButton"}),n&&!f.value&&t.isPortalled.value&&R(z,{id:M,features:J.Focusable,"data-headlessui-focus-guard":!0,as:"button",type:"button",onFocus:i})])}}}),$e=K({name:"PopoverOverlay",props:{as:{type:[Object,String],default:"div"},static:{type:Boolean,default:!1},unmount:{type:Boolean,default:!0}},setup(P,{attrs:b,slots:p}){let h=V("PopoverOverlay"),t=`headlessui-popover-overlay-${L()}`,e=ne(),c=T(()=>e!==null?(e.value&x.Open)===x.Open:h.popoverState.value===0);function d(){h.closePopover()}return()=>{let O={open:h.popoverState.value===0};return G({ourProps:{id:t,"aria-hidden":!0,onClick:d},theirProps:P,slot:O,attrs:b,slots:p,features:W.RenderStrategy|W.Static,visible:c.value,name:"PopoverOverlay"})}}}),je=K({name:"PopoverPanel",props:{as:{type:[Object,String],default:"div"},static:{type:Boolean,default:!1},unmount:{type:Boolean,default:!0},focus:{type:Boolean,default:!1},id:{type:String,default:()=>`headlessui-popover-panel-${L()}`}},inheritAttrs:!1,setup(P,{attrs:b,slots:p,expose:h}){let{focus:t}=P,e=V("PopoverPanel"),c=T(()=>A(e.panel)),d=`headlessui-focus-sentinel-before-${L()}`,O=`headlessui-focus-sentinel-after-${L()}`;h({el:e.panel,$el:e.panel}),ee(()=>{e.panelId.value=P.id}),te(()=>{e.panelId.value=null}),U(ue,e.panelId),q(()=>{var u,i;if(!t||e.popoverState.value!==0||!e.panel)return;let s=(u=c.value)==null?void 0:u.activeElement;(i=r(e.panel))!=null&&i.contains(s)||B(r(e.panel),C.First)});let f=ne(),y=T(()=>f!==null?(f.value&x.Open)===x.Open:e.popoverState.value===0);function M(s){var u,i;switch(s.key){case D.Escape:if(e.popoverState.value!==0||!r(e.panel)||c.value&&!((u=r(e.panel))!=null&&u.contains(c.value.activeElement)))return;s.preventDefault(),s.stopPropagation(),e.closePopover(),(i=r(e.button))==null||i.focus();break}}function l(s){var i,n,v,o,a;let u=s.relatedTarget;u&&r(e.panel)&&((i=r(e.panel))!=null&&i.contains(u)||(e.closePopover(),((v=(n=r(e.beforePanelSentinel))==null?void 0:n.contains)!=null&&v.call(n,u)||(a=(o=r(e.afterPanelSentinel))==null?void 0:o.contains)!=null&&a.call(o,u))&&u.focus({preventScroll:!0})))}let m=oe();function S(){let s=r(e.panel);if(!s)return;function u(){H(m.value,{[w.Forwards]:()=>{var n;B(s,C.First)===Q.Error&&((n=r(e.afterPanelSentinel))==null||n.focus())},[w.Backwards]:()=>{var i;(i=r(e.button))==null||i.focus({preventScroll:!0})}})}u()}function I(){let s=r(e.panel);if(!s)return;function u(){H(m.value,{[w.Forwards]:()=>{let i=r(e.button),n=r(e.panel);if(!i)return;let v=X(),o=v.indexOf(i),a=v.slice(0,o+1),E=[...v.slice(o+1),...a];for(let N of E.slice())if(N.dataset.headlessuiFocusGuard==="true"||n!=null&&n.contains(N)){let $=E.indexOf(N);$!==-1&&E.splice($,1)}B(E,C.First,{sorted:!1})},[w.Backwards]:()=>{var n;B(s,C.Previous)===Q.Error&&((n=r(e.button))==null||n.focus())}})}u()}return()=>{let s={open:e.popoverState.value===0,close:e.close},{id:u,focus:i,...n}=P,v={ref:e.panel,id:u,onKeydown:M,onFocusout:t&&e.popoverState.value===0?l:void 0,tabIndex:-1};return G({ourProps:v,theirProps:{...b,...n},attrs:b,slot:s,slots:{...p,default:(...o)=>{var a;return[R(j,[y.value&&e.isPortalled.value&&R(z,{id:d,ref:e.beforePanelSentinel,features:J.Focusable,"data-headlessui-focus-guard":!0,as:"button",type:"button",onFocus:S}),(a=p.default)==null?void 0:a.call(p,...o),y.value&&e.isPortalled.value&&R(z,{id:O,ref:e.afterPanelSentinel,features:J.Focusable,"data-headlessui-focus-guard":!0,as:"button",type:"button",onFocus:I})])]}},features:W.RenderStrategy|W.Static,visible:y.value,name:"PopoverPanel"})}}}),Ae=K({name:"PopoverGroup",inheritAttrs:!1,props:{as:{type:[Object,String],default:"div"}},setup(P,{attrs:b,slots:p,expose:h}){let t=F(null),e=ie([]),c=T(()=>A(t)),d=ce();h({el:t,$el:t});function O(l){let m=e.value.indexOf(l);m!==-1&&e.value.splice(m,1)}function f(l){return e.value.push(l),()=>{O(l)}}function y(){var S;let l=c.value;if(!l)return!1;let m=l.activeElement;return(S=r(t))!=null&&S.contains(m)?!0:e.value.some(I=>{var s,u;return((s=l.getElementById(I.buttonId.value))==null?void 0:s.contains(m))||((u=l.getElementById(I.panelId.value))==null?void 0:u.contains(m))})}function M(l){for(let m of e.value)m.buttonId.value!==l&&m.close()}return U(le,{registerPopover:f,unregisterPopover:O,isFocusWithinPopoverGroup:y,closeOthers:M,mainTreeNodeRef:d.mainTreeNodeRef}),()=>R(j,[G({ourProps:{ref:t},theirProps:{...P,...b},slot:{},attrs:b,slots:p,name:"PopoverGroup"}),R(d.MainTreeNode)])}});export{ye as Popover,Ge as PopoverButton,Ae as PopoverGroup,$e as PopoverOverlay,je as PopoverPanel}; |
@@ -1,1 +0,1 @@ | ||
import{computed as M,defineComponent as s,getCurrentInstance as L,h as j,inject as f,onMounted as w,onUnmounted as y,provide as T,reactive as I,ref as p,Teleport as b,watch as R,watchEffect as G}from"vue";import{usePortalRoot as O}from'../../internal/portal-force-root.js';import{dom as D}from'../../utils/dom.js';import{getOwnerDocument as E}from'../../utils/owner.js';import{render as h}from'../../utils/render.js';function x(r){let e=E(r);if(!e){if(r===null)return null;throw new Error(`[Headless UI]: Cannot find ownerDocument for contextElement: ${r}`)}let u=e.getElementById("headlessui-portal-root");if(u)return u;let t=e.createElement("div");return t.setAttribute("id","headlessui-portal-root"),e.body.appendChild(t)}let _=s({name:"Portal",props:{as:{type:[Object,String],default:"div"}},setup(r,{slots:e,attrs:u}){let t=p(null),i=M(()=>E(t)),l=O(),n=f(C,null),o=p(l===!0||n==null?x(t.value):n.resolveTarget()),d=p(!1);w(()=>{d.value=!0}),G(()=>{l||n!=null&&(o.value=n.resolveTarget())});let c=f(m,null),v=!1,H=L();return R(t,()=>{if(v||!c)return;let a=D(t);a&&(y(c.register(a),H),v=!0)}),y(()=>{var g,P;let a=(g=i.value)==null?void 0:g.getElementById("headlessui-portal-root");a&&o.value===a&&o.value.children.length<=0&&((P=o.value.parentElement)==null||P.removeChild(o.value))}),()=>{if(!d.value||o.value===null)return null;let a={ref:t,"data-headlessui-portal":""};return j(b,{to:o.value},h({ourProps:a,theirProps:r,slot:{},attrs:u,slots:e,name:"Portal"}))}}}),m=Symbol("PortalParentContext");function A(){let r=f(m,null),e=p([]);function u(l){return e.value.push(l),r&&r.register(l),()=>t(l)}function t(l){let n=e.value.indexOf(l);n!==-1&&e.value.splice(n,1),r&&r.unregister(l)}let i={register:u,unregister:t,portals:e};return[e,s({name:"PortalWrapper",setup(l,{slots:n}){return T(m,i),()=>{var o;return(o=n.default)==null?void 0:o.call(n)}}})]}let C=Symbol("PortalGroupContext"),N=s({name:"PortalGroup",props:{as:{type:[Object,String],default:"template"},target:{type:Object,default:null}},setup(r,{attrs:e,slots:u}){let t=I({resolveTarget(){return r.target}});return T(C,t),()=>{let{target:i,...l}=r;return h({theirProps:l,ourProps:{},slot:{},attrs:e,slots:u,name:"PortalGroup"})}}});export{_ as Portal,N as PortalGroup,A as useNestedPortals}; | ||
import{Teleport as M,computed as L,defineComponent as s,getCurrentInstance as j,h as w,inject as f,onMounted as I,onUnmounted as y,provide as T,reactive as b,ref as p,watch as R,watchEffect as G}from"vue";import{usePortalRoot as O}from'../../internal/portal-force-root.js';import{dom as D}from'../../utils/dom.js';import{getOwnerDocument as E}from'../../utils/owner.js';import{render as h}from'../../utils/render.js';function x(r){let e=E(r);if(!e){if(r===null)return null;throw new Error(`[Headless UI]: Cannot find ownerDocument for contextElement: ${r}`)}let u=e.getElementById("headlessui-portal-root");if(u)return u;let t=e.createElement("div");return t.setAttribute("id","headlessui-portal-root"),e.body.appendChild(t)}let _=s({name:"Portal",props:{as:{type:[Object,String],default:"div"}},setup(r,{slots:e,attrs:u}){let t=p(null),i=L(()=>E(t)),l=O(),n=f(C,null),o=p(l===!0||n==null?x(t.value):n.resolveTarget()),d=p(!1);I(()=>{d.value=!0}),G(()=>{l||n!=null&&(o.value=n.resolveTarget())});let c=f(m,null),v=!1,H=j();return R(t,()=>{if(v||!c)return;let a=D(t);a&&(y(c.register(a),H),v=!0)}),y(()=>{var g,P;let a=(g=i.value)==null?void 0:g.getElementById("headlessui-portal-root");a&&o.value===a&&o.value.children.length<=0&&((P=o.value.parentElement)==null||P.removeChild(o.value))}),()=>{if(!d.value||o.value===null)return null;let a={ref:t,"data-headlessui-portal":""};return w(M,{to:o.value},h({ourProps:a,theirProps:r,slot:{},attrs:u,slots:e,name:"Portal"}))}}}),m=Symbol("PortalParentContext");function A(){let r=f(m,null),e=p([]);function u(l){return e.value.push(l),r&&r.register(l),()=>t(l)}function t(l){let n=e.value.indexOf(l);n!==-1&&e.value.splice(n,1),r&&r.unregister(l)}let i={register:u,unregister:t,portals:e};return[e,s({name:"PortalWrapper",setup(l,{slots:n}){return T(m,i),()=>{var o;return(o=n.default)==null?void 0:o.call(n)}}})]}let C=Symbol("PortalGroupContext"),N=s({name:"PortalGroup",props:{as:{type:[Object,String],default:"template"},target:{type:Object,default:null}},setup(r,{attrs:e,slots:u}){let t=b({resolveTarget(){return r.target}});return T(C,t),()=>{let{target:i,...l}=r;return h({theirProps:l,ourProps:{},slot:{},attrs:e,slots:u,name:"PortalGroup"})}}});export{_ as Portal,N as PortalGroup,A as useNestedPortals}; |
@@ -154,4 +154,4 @@ declare function defaultComparator<T>(a: T, z: T): boolean; | ||
}>>, { | ||
passive: boolean; | ||
id: string; | ||
passive: boolean; | ||
as: string | Record<string, any>; | ||
@@ -158,0 +158,0 @@ }>; |
@@ -1,1 +0,1 @@ | ||
import{computed as o,defineComponent as A,Fragment as M,h as F,inject as _,onMounted as C,onUnmounted as $,provide as U,ref as h,toRaw as y,watch as W}from"vue";import{useControllable as J}from'../../hooks/use-controllable.js';import{useId as D}from'../../hooks/use-id.js';import{useTreeWalker as q}from'../../hooks/use-tree-walker.js';import{Features as Q,Hidden as X}from'../../internal/hidden.js';import{Keys as g}from'../../keyboard.js';import{dom as O}from'../../utils/dom.js';import{Focus as k,focusIn as x,FocusResult as I,sortByDomNode as Y}from'../../utils/focus-management.js';import{attemptSubmit as Z,objectToFormEntries as z}from'../../utils/form.js';import{getOwnerDocument as L}from'../../utils/owner.js';import{compact as ee,omit as te,render as P}from'../../utils/render.js';import{Description as ae,useDescriptions as B}from'../description/description.js';import{Label as ne,useLabels as V}from'../label/label.js';function re(t,c){return t===c}let j=Symbol("RadioGroupContext");function H(t){let c=_(j,null);if(c===null){let u=new Error(`<${t} /> is missing a parent <RadioGroup /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(u,H),u}return c}let ge=A({name:"RadioGroup",emits:{"update:modelValue":t=>!0},props:{as:{type:[Object,String],default:"div"},disabled:{type:[Boolean],default:!1},by:{type:[String,Function],default:()=>re},modelValue:{type:[Object,String,Number,Boolean],default:void 0},defaultValue:{type:[Object,String,Number,Boolean],default:void 0},form:{type:String,optional:!0},name:{type:String,optional:!0},id:{type:String,default:()=>`headlessui-radiogroup-${D()}`}},inheritAttrs:!1,setup(t,{emit:c,attrs:u,slots:E,expose:d}){let s=h(null),i=h([]),R=V({name:"RadioGroupLabel"}),w=B({name:"RadioGroupDescription"});d({el:s,$el:s});let[f,S]=J(o(()=>t.modelValue),e=>c("update:modelValue",e),o(()=>t.defaultValue)),p={options:i,value:f,disabled:o(()=>t.disabled),firstOption:o(()=>i.value.find(e=>!e.propsRef.disabled)),containsCheckedOption:o(()=>i.value.some(e=>p.compare(y(e.propsRef.value),y(t.modelValue)))),compare(e,a){if(typeof t.by=="string"){let n=t.by;return(e==null?void 0:e[n])===(a==null?void 0:a[n])}return t.by(e,a)},change(e){var n;if(t.disabled||p.compare(y(f.value),y(e)))return!1;let a=(n=i.value.find(l=>p.compare(y(l.propsRef.value),y(e))))==null?void 0:n.propsRef;return a!=null&&a.disabled?!1:(S(e),!0)},registerOption(e){i.value.push(e),i.value=Y(i.value,a=>a.element)},unregisterOption(e){let a=i.value.findIndex(n=>n.id===e);a!==-1&&i.value.splice(a,1)}};U(j,p),q({container:o(()=>O(s)),accept(e){return e.getAttribute("role")==="radio"?NodeFilter.FILTER_REJECT:e.hasAttribute("role")?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT},walk(e){e.setAttribute("role","none")}});function m(e){if(!s.value||!s.value.contains(e.target))return;let a=i.value.filter(n=>n.propsRef.disabled===!1).map(n=>n.element);switch(e.key){case g.Enter:Z(e.currentTarget);break;case g.ArrowLeft:case g.ArrowUp:if(e.preventDefault(),e.stopPropagation(),x(a,k.Previous|k.WrapAround)===I.Success){let l=i.value.find(r=>{var b;return r.element===((b=L(s))==null?void 0:b.activeElement)});l&&p.change(l.propsRef.value)}break;case g.ArrowRight:case g.ArrowDown:if(e.preventDefault(),e.stopPropagation(),x(a,k.Next|k.WrapAround)===I.Success){let l=i.value.find(r=>{var b;return r.element===((b=L(r.element))==null?void 0:b.activeElement)});l&&p.change(l.propsRef.value)}break;case g.Space:{e.preventDefault(),e.stopPropagation();let n=i.value.find(l=>{var r;return l.element===((r=L(l.element))==null?void 0:r.activeElement)});n&&p.change(n.propsRef.value)}break}}let v=o(()=>{var e;return(e=O(s))==null?void 0:e.closest("form")});return C(()=>{W([v],()=>{if(!v.value||t.defaultValue===void 0)return;function e(){p.change(t.defaultValue)}return v.value.addEventListener("reset",e),()=>{var a;(a=v.value)==null||a.removeEventListener("reset",e)}},{immediate:!0})}),()=>{let{disabled:e,name:a,id:n,form:l,...r}=t,b={ref:s,id:n,role:"radiogroup","aria-labelledby":R.value,"aria-describedby":w.value,onKeydown:m};return F(M,[...a!=null&&f.value!=null?z({[a]:f.value}).map(([T,G])=>F(X,ee({features:Q.Hidden,key:T,as:"input",type:"hidden",hidden:!0,readOnly:!0,form:l,name:T,value:G}))):[],P({ourProps:b,theirProps:{...u,...te(r,["modelValue","defaultValue","by"])},slot:{},attrs:u,slots:E,name:"RadioGroup"})])}}});var ie=(u=>(u[u.Empty=1]="Empty",u[u.Active=2]="Active",u))(ie||{});let he=A({name:"RadioGroupOption",props:{as:{type:[Object,String],default:"div"},value:{type:[Object,String,Number,Boolean]},disabled:{type:Boolean,default:!1},id:{type:String,default:()=>`headlessui-radiogroup-option-${D()}`}},setup(t,{attrs:c,slots:u,expose:E}){let d=H("RadioGroupOption"),s=V({name:"RadioGroupLabel"}),i=B({name:"RadioGroupDescription"}),R=h(null),w=o(()=>({value:t.value,disabled:t.disabled})),f=h(1);E({el:R,$el:R});let S=o(()=>O(R));C(()=>d.registerOption({id:t.id,element:S,propsRef:w})),$(()=>d.unregisterOption(t.id));let p=o(()=>{var r;return((r=d.firstOption.value)==null?void 0:r.id)===t.id}),m=o(()=>d.disabled.value||t.disabled),v=o(()=>d.compare(y(d.value.value),y(t.value))),e=o(()=>m.value?-1:v.value||!d.containsCheckedOption.value&&p.value?0:-1);function a(){var r;d.change(t.value)&&(f.value|=2,(r=O(R))==null||r.focus())}function n(){f.value|=2}function l(){f.value&=-3}return()=>{let{id:r,value:b,disabled:T,...G}=t,N={checked:v.value,disabled:m.value,active:Boolean(f.value&2)},K={id:r,ref:R,role:"radio","aria-checked":v.value?"true":"false","aria-labelledby":s.value,"aria-describedby":i.value,"aria-disabled":m.value?!0:void 0,tabIndex:e.value,onClick:m.value?void 0:a,onFocus:m.value?void 0:n,onBlur:m.value?void 0:l};return P({ourProps:K,theirProps:G,slot:N,attrs:c,slots:u,name:"RadioGroupOption"})}}}),Oe=ne,ke=ae;export{ge as RadioGroup,ke as RadioGroupDescription,Oe as RadioGroupLabel,he as RadioGroupOption}; | ||
import{Fragment as M,computed as o,defineComponent as A,h as F,inject as _,onMounted as C,onUnmounted as $,provide as U,ref as h,toRaw as y,watch as W}from"vue";import{useControllable as J}from'../../hooks/use-controllable.js';import{useId as D}from'../../hooks/use-id.js';import{useTreeWalker as q}from'../../hooks/use-tree-walker.js';import{Hidden as Q,Features as X}from'../../internal/hidden.js';import{Keys as g}from'../../keyboard.js';import{dom as O}from'../../utils/dom.js';import{Focus as k,FocusResult as x,focusIn as I,sortByDomNode as Y}from'../../utils/focus-management.js';import{attemptSubmit as Z,objectToFormEntries as z}from'../../utils/form.js';import{getOwnerDocument as L}from'../../utils/owner.js';import{compact as ee,omit as te,render as P}from'../../utils/render.js';import{Description as ae,useDescriptions as B}from'../description/description.js';import{Label as ne,useLabels as V}from'../label/label.js';function re(t,c){return t===c}let j=Symbol("RadioGroupContext");function H(t){let c=_(j,null);if(c===null){let u=new Error(`<${t} /> is missing a parent <RadioGroup /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(u,H),u}return c}let ge=A({name:"RadioGroup",emits:{"update:modelValue":t=>!0},props:{as:{type:[Object,String],default:"div"},disabled:{type:[Boolean],default:!1},by:{type:[String,Function],default:()=>re},modelValue:{type:[Object,String,Number,Boolean],default:void 0},defaultValue:{type:[Object,String,Number,Boolean],default:void 0},form:{type:String,optional:!0},name:{type:String,optional:!0},id:{type:String,default:()=>`headlessui-radiogroup-${D()}`}},inheritAttrs:!1,setup(t,{emit:c,attrs:u,slots:E,expose:d}){let s=h(null),i=h([]),R=V({name:"RadioGroupLabel"}),w=B({name:"RadioGroupDescription"});d({el:s,$el:s});let[f,S]=J(o(()=>t.modelValue),e=>c("update:modelValue",e),o(()=>t.defaultValue)),p={options:i,value:f,disabled:o(()=>t.disabled),firstOption:o(()=>i.value.find(e=>!e.propsRef.disabled)),containsCheckedOption:o(()=>i.value.some(e=>p.compare(y(e.propsRef.value),y(t.modelValue)))),compare(e,a){if(typeof t.by=="string"){let n=t.by;return(e==null?void 0:e[n])===(a==null?void 0:a[n])}return t.by(e,a)},change(e){var n;if(t.disabled||p.compare(y(f.value),y(e)))return!1;let a=(n=i.value.find(l=>p.compare(y(l.propsRef.value),y(e))))==null?void 0:n.propsRef;return a!=null&&a.disabled?!1:(S(e),!0)},registerOption(e){i.value.push(e),i.value=Y(i.value,a=>a.element)},unregisterOption(e){let a=i.value.findIndex(n=>n.id===e);a!==-1&&i.value.splice(a,1)}};U(j,p),q({container:o(()=>O(s)),accept(e){return e.getAttribute("role")==="radio"?NodeFilter.FILTER_REJECT:e.hasAttribute("role")?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT},walk(e){e.setAttribute("role","none")}});function m(e){if(!s.value||!s.value.contains(e.target))return;let a=i.value.filter(n=>n.propsRef.disabled===!1).map(n=>n.element);switch(e.key){case g.Enter:Z(e.currentTarget);break;case g.ArrowLeft:case g.ArrowUp:if(e.preventDefault(),e.stopPropagation(),I(a,k.Previous|k.WrapAround)===x.Success){let l=i.value.find(r=>{var b;return r.element===((b=L(s))==null?void 0:b.activeElement)});l&&p.change(l.propsRef.value)}break;case g.ArrowRight:case g.ArrowDown:if(e.preventDefault(),e.stopPropagation(),I(a,k.Next|k.WrapAround)===x.Success){let l=i.value.find(r=>{var b;return r.element===((b=L(r.element))==null?void 0:b.activeElement)});l&&p.change(l.propsRef.value)}break;case g.Space:{e.preventDefault(),e.stopPropagation();let n=i.value.find(l=>{var r;return l.element===((r=L(l.element))==null?void 0:r.activeElement)});n&&p.change(n.propsRef.value)}break}}let v=o(()=>{var e;return(e=O(s))==null?void 0:e.closest("form")});return C(()=>{W([v],()=>{if(!v.value||t.defaultValue===void 0)return;function e(){p.change(t.defaultValue)}return v.value.addEventListener("reset",e),()=>{var a;(a=v.value)==null||a.removeEventListener("reset",e)}},{immediate:!0})}),()=>{let{disabled:e,name:a,id:n,form:l,...r}=t,b={ref:s,id:n,role:"radiogroup","aria-labelledby":R.value,"aria-describedby":w.value,onKeydown:m};return F(M,[...a!=null&&f.value!=null?z({[a]:f.value}).map(([T,G])=>F(Q,ee({features:X.Hidden,key:T,as:"input",type:"hidden",hidden:!0,readOnly:!0,form:l,disabled:e,name:T,value:G}))):[],P({ourProps:b,theirProps:{...u,...te(r,["modelValue","defaultValue","by"])},slot:{},attrs:u,slots:E,name:"RadioGroup"})])}}});var ie=(u=>(u[u.Empty=1]="Empty",u[u.Active=2]="Active",u))(ie||{});let he=A({name:"RadioGroupOption",props:{as:{type:[Object,String],default:"div"},value:{type:[Object,String,Number,Boolean]},disabled:{type:Boolean,default:!1},id:{type:String,default:()=>`headlessui-radiogroup-option-${D()}`}},setup(t,{attrs:c,slots:u,expose:E}){let d=H("RadioGroupOption"),s=V({name:"RadioGroupLabel"}),i=B({name:"RadioGroupDescription"}),R=h(null),w=o(()=>({value:t.value,disabled:t.disabled})),f=h(1);E({el:R,$el:R});let S=o(()=>O(R));C(()=>d.registerOption({id:t.id,element:S,propsRef:w})),$(()=>d.unregisterOption(t.id));let p=o(()=>{var r;return((r=d.firstOption.value)==null?void 0:r.id)===t.id}),m=o(()=>d.disabled.value||t.disabled),v=o(()=>d.compare(y(d.value.value),y(t.value))),e=o(()=>m.value?-1:v.value||!d.containsCheckedOption.value&&p.value?0:-1);function a(){var r;d.change(t.value)&&(f.value|=2,(r=O(R))==null||r.focus())}function n(){f.value|=2}function l(){f.value&=-3}return()=>{let{id:r,value:b,disabled:T,...G}=t,N={checked:v.value,disabled:m.value,active:!!(f.value&2)},K={id:r,ref:R,role:"radio","aria-checked":v.value?"true":"false","aria-labelledby":s.value,"aria-describedby":i.value,"aria-disabled":m.value?!0:void 0,tabIndex:e.value,onClick:m.value?void 0:a,onFocus:m.value?void 0:n,onBlur:m.value?void 0:l};return P({ourProps:K,theirProps:G,slot:N,attrs:c,slots:u,name:"RadioGroupOption"})}}}),Oe=ne,ke=ae;export{ge as RadioGroup,ke as RadioGroupDescription,Oe as RadioGroupLabel,he as RadioGroupOption}; |
@@ -47,2 +47,10 @@ export declare let SwitchGroup: import("vue").DefineComponent<{ | ||
}; | ||
disabled: { | ||
type: BooleanConstructor; | ||
default: boolean; | ||
}; | ||
tabIndex: { | ||
type: NumberConstructor; | ||
default: number; | ||
}; | ||
}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, { | ||
@@ -81,2 +89,10 @@ [key: string]: any; | ||
}; | ||
disabled: { | ||
type: BooleanConstructor; | ||
default: boolean; | ||
}; | ||
tabIndex: { | ||
type: NumberConstructor; | ||
default: number; | ||
}; | ||
}>> & { | ||
@@ -86,3 +102,5 @@ "onUpdate:modelValue"?: ((_value: boolean) => any) | undefined; | ||
id: string; | ||
tabIndex: number; | ||
as: string | Record<string, any>; | ||
disabled: boolean; | ||
modelValue: boolean; | ||
@@ -122,4 +140,4 @@ defaultChecked: boolean; | ||
}>>, { | ||
passive: boolean; | ||
id: string; | ||
passive: boolean; | ||
as: string | Record<string, any>; | ||
@@ -126,0 +144,0 @@ }>; |
@@ -1,1 +0,1 @@ | ||
import{computed as d,defineComponent as m,Fragment as T,h,inject as H,onMounted as M,provide as B,ref as y,watch as P}from"vue";import{useControllable as j}from'../../hooks/use-controllable.js';import{useId as G}from'../../hooks/use-id.js';import{useResolveButtonType as V}from'../../hooks/use-resolve-button-type.js';import{Features as F,Hidden as I}from'../../internal/hidden.js';import{Keys as b}from'../../keyboard.js';import{dom as O}from'../../utils/dom.js';import{attemptSubmit as A}from'../../utils/form.js';import{compact as $,omit as N,render as v}from'../../utils/render.js';import{Description as U,useDescriptions as _}from'../description/description.js';import{Label as q,useLabels as z}from'../label/label.js';let S=Symbol("GroupContext"),oe=m({name:"SwitchGroup",props:{as:{type:[Object,String],default:"template"}},setup(l,{slots:p,attrs:a}){let o=y(null),f=z({name:"SwitchLabel",props:{htmlFor:d(()=>{var r;return(r=o.value)==null?void 0:r.id}),onClick(r){o.value&&(r.currentTarget.tagName==="LABEL"&&r.preventDefault(),o.value.click(),o.value.focus({preventScroll:!0}))}}}),t=_({name:"SwitchDescription"});return B(S,{switchRef:o,labelledby:f,describedby:t}),()=>v({theirProps:l,ourProps:{},slot:{},slots:p,attrs:a,name:"SwitchGroup"})}}),ie=m({name:"Switch",emits:{"update:modelValue":l=>!0},props:{as:{type:[Object,String],default:"button"},modelValue:{type:Boolean,default:void 0},defaultChecked:{type:Boolean,optional:!0},form:{type:String,optional:!0},name:{type:String,optional:!0},value:{type:String,optional:!0},id:{type:String,default:()=>`headlessui-switch-${G()}`}},inheritAttrs:!1,setup(l,{emit:p,attrs:a,slots:o,expose:f}){let t=H(S,null),[i,r]=j(d(()=>l.modelValue),e=>p("update:modelValue",e),d(()=>l.defaultChecked));function s(){r(!i.value)}let w=y(null),u=t===null?w:t.switchRef,g=V(d(()=>({as:l.as,type:a.type})),u);f({el:u,$el:u});function k(e){e.preventDefault(),s()}function C(e){e.key===b.Space?(e.preventDefault(),s()):e.key===b.Enter&&A(e.currentTarget)}function E(e){e.preventDefault()}let c=d(()=>{var e,n;return(n=(e=O(u))==null?void 0:e.closest)==null?void 0:n.call(e,"form")});return M(()=>{P([c],()=>{if(!c.value||l.defaultChecked===void 0)return;function e(){r(l.defaultChecked)}return c.value.addEventListener("reset",e),()=>{var n;(n=c.value)==null||n.removeEventListener("reset",e)}},{immediate:!0})}),()=>{let{id:e,name:n,value:L,form:D,...R}=l,K={checked:i.value},x={id:e,ref:u,role:"switch",type:g.value,tabIndex:0,"aria-checked":i.value,"aria-labelledby":t==null?void 0:t.labelledby.value,"aria-describedby":t==null?void 0:t.describedby.value,onClick:k,onKeyup:C,onKeypress:E};return h(T,[n!=null&&i.value!=null?h(I,$({features:F.Hidden,as:"input",type:"checkbox",hidden:!0,readOnly:!0,checked:i.value,form:D,name:n,value:L})):null,v({ourProps:x,theirProps:{...a,...N(R,["modelValue","defaultChecked"])},slot:K,attrs:a,slots:o,name:"Switch"})])}}}),ae=q,ue=U;export{ie as Switch,ue as SwitchDescription,oe as SwitchGroup,ae as SwitchLabel}; | ||
import{Fragment as B,computed as d,defineComponent as y,h as b,inject as H,onMounted as M,provide as I,ref as v,watch as P}from"vue";import{useControllable as j}from'../../hooks/use-controllable.js';import{useId as G}from'../../hooks/use-id.js';import{useResolveButtonType as V}from'../../hooks/use-resolve-button-type.js';import{Hidden as F,Features as O}from'../../internal/hidden.js';import{Keys as S}from'../../keyboard.js';import{dom as A}from'../../utils/dom.js';import{attemptSubmit as N}from'../../utils/form.js';import{compact as $,omit as U,render as w}from'../../utils/render.js';import{Description as _,useDescriptions as q}from'../description/description.js';import{Label as z,useLabels as J}from'../label/label.js';let g=Symbol("GroupContext"),ie=y({name:"SwitchGroup",props:{as:{type:[Object,String],default:"template"}},setup(l,{slots:p,attrs:o}){let a=v(null),f=J({name:"SwitchLabel",props:{htmlFor:d(()=>{var n;return(n=a.value)==null?void 0:n.id}),onClick(n){a.value&&(n.currentTarget.tagName==="LABEL"&&n.preventDefault(),a.value.click(),a.value.focus({preventScroll:!0}))}}}),t=q({name:"SwitchDescription"});return I(g,{switchRef:a,labelledby:f,describedby:t}),()=>w({theirProps:l,ourProps:{},slot:{},slots:p,attrs:o,name:"SwitchGroup"})}}),oe=y({name:"Switch",emits:{"update:modelValue":l=>!0},props:{as:{type:[Object,String],default:"button"},modelValue:{type:Boolean,default:void 0},defaultChecked:{type:Boolean,optional:!0},form:{type:String,optional:!0},name:{type:String,optional:!0},value:{type:String,optional:!0},id:{type:String,default:()=>`headlessui-switch-${G()}`},disabled:{type:Boolean,default:!1},tabIndex:{type:Number,default:0}},inheritAttrs:!1,setup(l,{emit:p,attrs:o,slots:a,expose:f}){let t=H(g,null),[i,n]=j(d(()=>l.modelValue),e=>p("update:modelValue",e),d(()=>l.defaultChecked));function s(){n(!i.value)}let k=v(null),u=t===null?k:t.switchRef,C=V(d(()=>({as:l.as,type:o.type})),u);f({el:u,$el:u});function E(e){e.preventDefault(),s()}function L(e){e.key===S.Space?(e.preventDefault(),s()):e.key===S.Enter&&N(e.currentTarget)}function D(e){e.preventDefault()}let c=d(()=>{var e,r;return(r=(e=A(u))==null?void 0:e.closest)==null?void 0:r.call(e,"form")});return M(()=>{P([c],()=>{if(!c.value||l.defaultChecked===void 0)return;function e(){n(l.defaultChecked)}return c.value.addEventListener("reset",e),()=>{var r;(r=c.value)==null||r.removeEventListener("reset",e)}},{immediate:!0})}),()=>{let{id:e,name:r,value:R,form:x,tabIndex:m,...h}=l,K={checked:i.value},T={id:e,ref:u,role:"switch",type:C.value,tabIndex:m===-1?0:m,"aria-checked":i.value,"aria-labelledby":t==null?void 0:t.labelledby.value,"aria-describedby":t==null?void 0:t.describedby.value,onClick:E,onKeyup:L,onKeypress:D};return b(B,[r!=null&&i.value!=null?b(F,$({features:O.Hidden,as:"input",type:"checkbox",hidden:!0,readOnly:!0,checked:i.value,form:x,disabled:h.disabled,name:r,value:R})):null,w({ourProps:T,theirProps:{...o,...U(h,["modelValue","defaultChecked"])},slot:K,attrs:o,slots:a,name:"Switch"})])}}}),ue=z,de=_;export{oe as Switch,de as SwitchDescription,ie as SwitchGroup,ue as SwitchLabel}; |
@@ -1,1 +0,1 @@ | ||
import{computed as c,defineComponent as D,Fragment as z,h as H,inject as A,onMounted as M,onUnmounted as K,provide as N,ref as T,watch as _,watchEffect as J}from"vue";import{useId as $}from'../../hooks/use-id.js';import{useResolveButtonType as Q}from'../../hooks/use-resolve-button-type.js';import{FocusSentinel as V}from'../../internal/focus-sentinel.js';import{Hidden as X}from'../../internal/hidden.js';import{Keys as x}from'../../keyboard.js';import{dom as o}from'../../utils/dom.js';import{Focus as I,focusIn as R,FocusResult as C,sortByDomNode as O}from'../../utils/focus-management.js';import{match as F}from'../../utils/match.js';import{microTask as Y}from'../../utils/micro-task.js';import{getOwnerDocument as Z}from'../../utils/owner.js';import{Features as q,omit as ee,render as L}from'../../utils/render.js';var te=(i=>(i[i.Forwards=0]="Forwards",i[i.Backwards=1]="Backwards",i))(te||{}),le=(s=>(s[s.Less=-1]="Less",s[s.Equal=0]="Equal",s[s.Greater=1]="Greater",s))(le||{});let U=Symbol("TabsContext");function k(a){let v=A(U,null);if(v===null){let i=new Error(`<${a} /> is missing a parent <TabGroup /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(i,k),i}return v}let j=Symbol("TabsSSRContext"),me=D({name:"TabGroup",emits:{change:a=>!0},props:{as:{type:[Object,String],default:"template"},selectedIndex:{type:[Number],default:null},defaultIndex:{type:[Number],default:0},vertical:{type:[Boolean],default:!1},manual:{type:[Boolean],default:!1}},inheritAttrs:!1,setup(a,{slots:v,attrs:i,emit:s}){var P;let l=T((P=a.selectedIndex)!=null?P:a.defaultIndex),n=T([]),d=T([]),h=c(()=>a.selectedIndex!==null),b=c(()=>h.value?a.selectedIndex:l.value);function m(t){var S;let e=O(r.tabs.value,o),u=O(r.panels.value,o),f=e.filter(p=>{var g;return!((g=o(p))!=null&&g.hasAttribute("disabled"))});if(t<0||t>e.length-1){let p=F(l.value===null?0:Math.sign(t-l.value),{[-1]:()=>1,[0]:()=>F(Math.sign(t),{[-1]:()=>0,[0]:()=>0,[1]:()=>1}),[1]:()=>0}),g=F(p,{[0]:()=>e.indexOf(f[0]),[1]:()=>e.indexOf(f[f.length-1])});g!==-1&&(l.value=g),r.tabs.value=e,r.panels.value=u}else{let p=e.slice(0,t),G=[...e.slice(t),...p].find(W=>f.includes(W));if(!G)return;let B=(S=e.indexOf(G))!=null?S:r.selectedIndex.value;B===-1&&(B=r.selectedIndex.value),l.value=B,r.tabs.value=e,r.panels.value=u}}let r={selectedIndex:c(()=>{var t,e;return(e=(t=l.value)!=null?t:a.defaultIndex)!=null?e:null}),orientation:c(()=>a.vertical?"vertical":"horizontal"),activation:c(()=>a.manual?"manual":"auto"),tabs:n,panels:d,setSelectedIndex(t){b.value!==t&&s("change",t),h.value||m(t)},registerTab(t){var f;if(n.value.includes(t))return;let e=n.value[l.value];n.value.push(t),n.value=O(n.value,o);let u=(f=n.value.indexOf(e))!=null?f:l.value;u!==-1&&(l.value=u)},unregisterTab(t){let e=n.value.indexOf(t);e!==-1&&n.value.splice(e,1)},registerPanel(t){d.value.includes(t)||(d.value.push(t),d.value=O(d.value,o))},unregisterPanel(t){let e=d.value.indexOf(t);e!==-1&&d.value.splice(e,1)}};N(U,r);let w=T({tabs:[],panels:[]}),y=T(!1);M(()=>{y.value=!0}),N(j,c(()=>y.value?null:w.value));let E=c(()=>a.selectedIndex);return M(()=>{_([E],()=>{var t;return m((t=a.selectedIndex)!=null?t:a.defaultIndex)},{immediate:!0})}),J(()=>{if(!h.value||b.value==null||r.tabs.value.length<=0)return;let t=O(r.tabs.value,o);t.some((u,f)=>o(r.tabs.value[f])!==o(u))&&r.setSelectedIndex(t.findIndex(u=>o(u)===o(r.tabs.value[b.value])))}),()=>{let t={selectedIndex:l.value};return H(z,[n.value.length<=0&&H(V,{onFocus:()=>{for(let e of n.value){let u=o(e);if((u==null?void 0:u.tabIndex)===0)return u.focus(),!0}return!1}}),L({theirProps:{...i,...ee(a,["selectedIndex","defaultIndex","manual","vertical","onChange"])},ourProps:{},slot:t,slots:v,attrs:i,name:"TabGroup"})])}}}),pe=D({name:"TabList",props:{as:{type:[Object,String],default:"div"}},setup(a,{attrs:v,slots:i}){let s=k("TabList");return()=>{let l={selectedIndex:s.selectedIndex.value},n={role:"tablist","aria-orientation":s.orientation.value};return L({ourProps:n,theirProps:a,slot:l,attrs:v,slots:i,name:"TabList"})}}}),xe=D({name:"Tab",props:{as:{type:[Object,String],default:"button"},disabled:{type:[Boolean],default:!1},id:{type:String,default:()=>`headlessui-tabs-tab-${$()}`}},setup(a,{attrs:v,slots:i,expose:s}){let l=k("Tab"),n=T(null);s({el:n,$el:n}),M(()=>l.registerTab(n)),K(()=>l.unregisterTab(n));let d=A(j),h=c(()=>{if(d.value){let e=d.value.tabs.indexOf(a.id);return e===-1?d.value.tabs.push(a.id)-1:e}return-1}),b=c(()=>{let e=l.tabs.value.indexOf(n);return e===-1?h.value:e}),m=c(()=>b.value===l.selectedIndex.value);function r(e){var f;let u=e();if(u===C.Success&&l.activation.value==="auto"){let S=(f=Z(n))==null?void 0:f.activeElement,p=l.tabs.value.findIndex(g=>o(g)===S);p!==-1&&l.setSelectedIndex(p)}return u}function w(e){let u=l.tabs.value.map(S=>o(S)).filter(Boolean);if(e.key===x.Space||e.key===x.Enter){e.preventDefault(),e.stopPropagation(),l.setSelectedIndex(b.value);return}switch(e.key){case x.Home:case x.PageUp:return e.preventDefault(),e.stopPropagation(),r(()=>R(u,I.First));case x.End:case x.PageDown:return e.preventDefault(),e.stopPropagation(),r(()=>R(u,I.Last))}if(r(()=>F(l.orientation.value,{vertical(){return e.key===x.ArrowUp?R(u,I.Previous|I.WrapAround):e.key===x.ArrowDown?R(u,I.Next|I.WrapAround):C.Error},horizontal(){return e.key===x.ArrowLeft?R(u,I.Previous|I.WrapAround):e.key===x.ArrowRight?R(u,I.Next|I.WrapAround):C.Error}}))===C.Success)return e.preventDefault()}let y=T(!1);function E(){var e;y.value||(y.value=!0,!a.disabled&&((e=o(n))==null||e.focus({preventScroll:!0}),l.setSelectedIndex(b.value),Y(()=>{y.value=!1})))}function P(e){e.preventDefault()}let t=Q(c(()=>({as:a.as,type:v.type})),n);return()=>{var p;let e={selected:m.value},{id:u,...f}=a,S={ref:n,onKeydown:w,onMousedown:P,onClick:E,id:u,role:"tab",type:t.value,"aria-controls":(p=o(l.panels.value[b.value]))==null?void 0:p.id,"aria-selected":m.value,tabIndex:m.value?0:-1,disabled:a.disabled?!0:void 0};return L({ourProps:S,theirProps:f,slot:e,attrs:v,slots:i,name:"Tab"})}}}),Ie=D({name:"TabPanels",props:{as:{type:[Object,String],default:"div"}},setup(a,{slots:v,attrs:i}){let s=k("TabPanels");return()=>{let l={selectedIndex:s.selectedIndex.value};return L({theirProps:a,ourProps:{},slot:l,attrs:i,slots:v,name:"TabPanels"})}}}),ye=D({name:"TabPanel",props:{as:{type:[Object,String],default:"div"},static:{type:Boolean,default:!1},unmount:{type:Boolean,default:!0},id:{type:String,default:()=>`headlessui-tabs-panel-${$()}`},tabIndex:{type:Number,default:0}},setup(a,{attrs:v,slots:i,expose:s}){let l=k("TabPanel"),n=T(null);s({el:n,$el:n}),M(()=>l.registerPanel(n)),K(()=>l.unregisterPanel(n));let d=A(j),h=c(()=>{if(d.value){let r=d.value.panels.indexOf(a.id);return r===-1?d.value.panels.push(a.id)-1:r}return-1}),b=c(()=>{let r=l.panels.value.indexOf(n);return r===-1?h.value:r}),m=c(()=>b.value===l.selectedIndex.value);return()=>{var t;let r={selected:m.value},{id:w,tabIndex:y,...E}=a,P={ref:n,id:w,role:"tabpanel","aria-labelledby":(t=o(l.tabs.value[b.value]))==null?void 0:t.id,tabIndex:m.value?y:-1};return!m.value&&a.unmount&&!a.static?H(X,{as:"span","aria-hidden":!0,...P}):L({ourProps:P,theirProps:E,slot:r,attrs:v,slots:i,features:q.Static|q.RenderStrategy,visible:m.value,name:"TabPanel"})}}});export{xe as Tab,me as TabGroup,pe as TabList,ye as TabPanel,Ie as TabPanels}; | ||
import{Fragment as z,computed as c,defineComponent as D,h as H,inject as A,onMounted as M,onUnmounted as K,provide as N,ref as h,watch as _,watchEffect as J}from"vue";import{useId as $}from'../../hooks/use-id.js';import{useResolveButtonType as Q}from'../../hooks/use-resolve-button-type.js';import{FocusSentinel as V}from'../../internal/focus-sentinel.js';import{Hidden as X}from'../../internal/hidden.js';import{Keys as I}from'../../keyboard.js';import{dom as o}from'../../utils/dom.js';import{Focus as y,FocusResult as C,focusIn as R,sortByDomNode as O}from'../../utils/focus-management.js';import{match as F}from'../../utils/match.js';import{microTask as Y}from'../../utils/micro-task.js';import{getOwnerDocument as Z}from'../../utils/owner.js';import{Features as q,omit as ee,render as L}from'../../utils/render.js';var te=(i=>(i[i.Forwards=0]="Forwards",i[i.Backwards=1]="Backwards",i))(te||{}),le=(s=>(s[s.Less=-1]="Less",s[s.Equal=0]="Equal",s[s.Greater=1]="Greater",s))(le||{});let U=Symbol("TabsContext");function k(a){let v=A(U,null);if(v===null){let i=new Error(`<${a} /> is missing a parent <TabGroup /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(i,k),i}return v}let j=Symbol("TabsSSRContext"),me=D({name:"TabGroup",emits:{change:a=>!0},props:{as:{type:[Object,String],default:"template"},selectedIndex:{type:[Number],default:null},defaultIndex:{type:[Number],default:0},vertical:{type:[Boolean],default:!1},manual:{type:[Boolean],default:!1}},inheritAttrs:!1,setup(a,{slots:v,attrs:i,emit:s}){var P;let l=h((P=a.selectedIndex)!=null?P:a.defaultIndex),n=h([]),d=h([]),S=c(()=>a.selectedIndex!==null),b=c(()=>S.value?a.selectedIndex:l.value);function m(t){var T;let e=O(r.tabs.value,o),u=O(r.panels.value,o),f=e.filter(p=>{var x;return!((x=o(p))!=null&&x.hasAttribute("disabled"))});if(t<0||t>e.length-1){let p=F(l.value===null?0:Math.sign(t-l.value),{[-1]:()=>1,[0]:()=>F(Math.sign(t),{[-1]:()=>0,[0]:()=>0,[1]:()=>1}),[1]:()=>0}),x=F(p,{[0]:()=>e.indexOf(f[0]),[1]:()=>e.indexOf(f[f.length-1])});x!==-1&&(l.value=x),r.tabs.value=e,r.panels.value=u}else{let p=e.slice(0,t),G=[...e.slice(t),...p].find(W=>f.includes(W));if(!G)return;let B=(T=e.indexOf(G))!=null?T:r.selectedIndex.value;B===-1&&(B=r.selectedIndex.value),l.value=B,r.tabs.value=e,r.panels.value=u}}let r={selectedIndex:c(()=>{var t,e;return(e=(t=l.value)!=null?t:a.defaultIndex)!=null?e:null}),orientation:c(()=>a.vertical?"vertical":"horizontal"),activation:c(()=>a.manual?"manual":"auto"),tabs:n,panels:d,setSelectedIndex(t){b.value!==t&&s("change",t),S.value||m(t)},registerTab(t){var u;if(n.value.includes(t))return;let e=n.value[l.value];if(n.value.push(t),n.value=O(n.value,o),!S.value){let f=(u=n.value.indexOf(e))!=null?u:l.value;f!==-1&&(l.value=f)}},unregisterTab(t){let e=n.value.indexOf(t);e!==-1&&n.value.splice(e,1)},registerPanel(t){d.value.includes(t)||(d.value.push(t),d.value=O(d.value,o))},unregisterPanel(t){let e=d.value.indexOf(t);e!==-1&&d.value.splice(e,1)}};N(U,r);let w=h({tabs:[],panels:[]}),g=h(!1);M(()=>{g.value=!0}),N(j,c(()=>g.value?null:w.value));let E=c(()=>a.selectedIndex);return M(()=>{_([E],()=>{var t;return m((t=a.selectedIndex)!=null?t:a.defaultIndex)},{immediate:!0})}),J(()=>{if(!S.value||b.value==null||r.tabs.value.length<=0)return;let t=O(r.tabs.value,o);t.some((u,f)=>o(r.tabs.value[f])!==o(u))&&r.setSelectedIndex(t.findIndex(u=>o(u)===o(r.tabs.value[b.value])))}),()=>{let t={selectedIndex:l.value};return H(z,[n.value.length<=0&&H(V,{onFocus:()=>{for(let e of n.value){let u=o(e);if((u==null?void 0:u.tabIndex)===0)return u.focus(),!0}return!1}}),L({theirProps:{...i,...ee(a,["selectedIndex","defaultIndex","manual","vertical","onChange"])},ourProps:{},slot:t,slots:v,attrs:i,name:"TabGroup"})])}}}),pe=D({name:"TabList",props:{as:{type:[Object,String],default:"div"}},setup(a,{attrs:v,slots:i}){let s=k("TabList");return()=>{let l={selectedIndex:s.selectedIndex.value},n={role:"tablist","aria-orientation":s.orientation.value};return L({ourProps:n,theirProps:a,slot:l,attrs:v,slots:i,name:"TabList"})}}}),xe=D({name:"Tab",props:{as:{type:[Object,String],default:"button"},disabled:{type:[Boolean],default:!1},id:{type:String,default:()=>`headlessui-tabs-tab-${$()}`}},setup(a,{attrs:v,slots:i,expose:s}){let l=k("Tab"),n=h(null);s({el:n,$el:n}),M(()=>l.registerTab(n)),K(()=>l.unregisterTab(n));let d=A(j),S=c(()=>{if(d.value){let e=d.value.tabs.indexOf(a.id);return e===-1?d.value.tabs.push(a.id)-1:e}return-1}),b=c(()=>{let e=l.tabs.value.indexOf(n);return e===-1?S.value:e}),m=c(()=>b.value===l.selectedIndex.value);function r(e){var f;let u=e();if(u===C.Success&&l.activation.value==="auto"){let T=(f=Z(n))==null?void 0:f.activeElement,p=l.tabs.value.findIndex(x=>o(x)===T);p!==-1&&l.setSelectedIndex(p)}return u}function w(e){let u=l.tabs.value.map(T=>o(T)).filter(Boolean);if(e.key===I.Space||e.key===I.Enter){e.preventDefault(),e.stopPropagation(),l.setSelectedIndex(b.value);return}switch(e.key){case I.Home:case I.PageUp:return e.preventDefault(),e.stopPropagation(),r(()=>R(u,y.First));case I.End:case I.PageDown:return e.preventDefault(),e.stopPropagation(),r(()=>R(u,y.Last))}if(r(()=>F(l.orientation.value,{vertical(){return e.key===I.ArrowUp?R(u,y.Previous|y.WrapAround):e.key===I.ArrowDown?R(u,y.Next|y.WrapAround):C.Error},horizontal(){return e.key===I.ArrowLeft?R(u,y.Previous|y.WrapAround):e.key===I.ArrowRight?R(u,y.Next|y.WrapAround):C.Error}}))===C.Success)return e.preventDefault()}let g=h(!1);function E(){var e;g.value||(g.value=!0,!a.disabled&&((e=o(n))==null||e.focus({preventScroll:!0}),l.setSelectedIndex(b.value),Y(()=>{g.value=!1})))}function P(e){e.preventDefault()}let t=Q(c(()=>({as:a.as,type:v.type})),n);return()=>{var p,x;let e={selected:m.value,disabled:(p=a.disabled)!=null?p:!1},{id:u,...f}=a,T={ref:n,onKeydown:w,onMousedown:P,onClick:E,id:u,role:"tab",type:t.value,"aria-controls":(x=o(l.panels.value[b.value]))==null?void 0:x.id,"aria-selected":m.value,tabIndex:m.value?0:-1,disabled:a.disabled?!0:void 0};return L({ourProps:T,theirProps:f,slot:e,attrs:v,slots:i,name:"Tab"})}}}),Ie=D({name:"TabPanels",props:{as:{type:[Object,String],default:"div"}},setup(a,{slots:v,attrs:i}){let s=k("TabPanels");return()=>{let l={selectedIndex:s.selectedIndex.value};return L({theirProps:a,ourProps:{},slot:l,attrs:i,slots:v,name:"TabPanels"})}}}),ye=D({name:"TabPanel",props:{as:{type:[Object,String],default:"div"},static:{type:Boolean,default:!1},unmount:{type:Boolean,default:!0},id:{type:String,default:()=>`headlessui-tabs-panel-${$()}`},tabIndex:{type:Number,default:0}},setup(a,{attrs:v,slots:i,expose:s}){let l=k("TabPanel"),n=h(null);s({el:n,$el:n}),M(()=>l.registerPanel(n)),K(()=>l.unregisterPanel(n));let d=A(j),S=c(()=>{if(d.value){let r=d.value.panels.indexOf(a.id);return r===-1?d.value.panels.push(a.id)-1:r}return-1}),b=c(()=>{let r=l.panels.value.indexOf(n);return r===-1?S.value:r}),m=c(()=>b.value===l.selectedIndex.value);return()=>{var t;let r={selected:m.value},{id:w,tabIndex:g,...E}=a,P={ref:n,id:w,role:"tabpanel","aria-labelledby":(t=o(l.tabs.value[b.value]))==null?void 0:t.id,tabIndex:m.value?g:-1};return!m.value&&a.unmount&&!a.static?H(X,{as:"span","aria-hidden":!0,...P}):L({ourProps:P,theirProps:E,slot:r,attrs:v,slots:i,features:q.Static|q.RenderStrategy,visible:m.value,name:"TabPanel"})}}});export{xe as Tab,me as TabGroup,pe as TabList,ye as TabPanel,Ie as TabPanels}; |
@@ -1,1 +0,1 @@ | ||
import{computed as w,defineComponent as K,h as k,inject as F,normalizeClass as ae,onMounted as C,onUnmounted as z,provide as B,ref as m,watch as le,watchEffect as x}from"vue";import{useId as ie}from'../../hooks/use-id.js';import{hasOpenClosed as se,State as u,useOpenClosed as oe,useOpenClosedProvider as ue}from'../../internal/open-closed.js';import{dom as $}from'../../utils/dom.js';import{env as fe}from'../../utils/env.js';import{match as O}from'../../utils/match.js';import{Features as de,omit as ve,render as q,RenderStrategy as T}from'../../utils/render.js';import{Reason as G,transition as J}from'./utils/transition.js';function g(e=""){return e.split(" ").filter(t=>t.trim().length>1)}let R=Symbol("TransitionContext");var pe=(a=>(a.Visible="visible",a.Hidden="hidden",a))(pe||{});function me(){return F(R,null)!==null}function Te(){let e=F(R,null);if(e===null)throw new Error("A <TransitionChild /> is used but it is missing a parent <TransitionRoot />.");return e}function ge(){let e=F(N,null);if(e===null)throw new Error("A <TransitionChild /> is used but it is missing a parent <TransitionRoot />.");return e}let N=Symbol("NestingContext");function L(e){return"children"in e?L(e.children):e.value.filter(({state:t})=>t==="visible").length>0}function Q(e){let t=m([]),a=m(!1);C(()=>a.value=!0),z(()=>a.value=!1);function s(n,r=T.Hidden){let l=t.value.findIndex(({id:f})=>f===n);l!==-1&&(O(r,{[T.Unmount](){t.value.splice(l,1)},[T.Hidden](){t.value[l].state="hidden"}}),!L(t)&&a.value&&(e==null||e()))}function h(n){let r=t.value.find(({id:l})=>l===n);return r?r.state!=="visible"&&(r.state="visible"):t.value.push({id:n,state:"visible"}),()=>s(n,T.Unmount)}return{children:t,register:h,unregister:s}}let W=de.RenderStrategy,he=K({props:{as:{type:[Object,String],default:"div"},show:{type:[Boolean],default:null},unmount:{type:[Boolean],default:!0},appear:{type:[Boolean],default:!1},enter:{type:[String],default:""},enterFrom:{type:[String],default:""},enterTo:{type:[String],default:""},entered:{type:[String],default:""},leave:{type:[String],default:""},leaveFrom:{type:[String],default:""},leaveTo:{type:[String],default:""}},emits:{beforeEnter:()=>!0,afterEnter:()=>!0,beforeLeave:()=>!0,afterLeave:()=>!0},setup(e,{emit:t,attrs:a,slots:s,expose:h}){let n=m(0);function r(){n.value|=u.Opening,t("beforeEnter")}function l(){n.value&=~u.Opening,t("afterEnter")}function f(){n.value|=u.Closing,t("beforeLeave")}function S(){n.value&=~u.Closing,t("afterLeave")}if(!me()&&se())return()=>k(Se,{...e,onBeforeEnter:r,onAfterEnter:l,onBeforeLeave:f,onAfterLeave:S},s);let d=m(null),y=w(()=>e.unmount?T.Unmount:T.Hidden);h({el:d,$el:d});let{show:v,appear:A}=Te(),{register:D,unregister:H}=ge(),i=m(v.value?"visible":"hidden"),I={value:!0},c=ie(),b={value:!1},P=Q(()=>{!b.value&&i.value!=="hidden"&&(i.value="hidden",H(c),S())});C(()=>{let o=D(c);z(o)}),x(()=>{if(y.value===T.Hidden&&c){if(v.value&&i.value!=="visible"){i.value="visible";return}O(i.value,{["hidden"]:()=>H(c),["visible"]:()=>D(c)})}});let j=g(e.enter),M=g(e.enterFrom),X=g(e.enterTo),_=g(e.entered),Y=g(e.leave),Z=g(e.leaveFrom),ee=g(e.leaveTo);C(()=>{x(()=>{if(i.value==="visible"){let o=$(d);if(o instanceof Comment&&o.data==="")throw new Error("Did you forget to passthrough the `ref` to the actual DOM node?")}})});function te(o){let E=I.value&&!A.value,p=$(d);!p||!(p instanceof HTMLElement)||E||(b.value=!0,v.value&&r(),v.value||f(),o(v.value?J(p,j,M,X,_,V=>{b.value=!1,V===G.Finished&&l()}):J(p,Y,Z,ee,_,V=>{b.value=!1,V===G.Finished&&(L(P)||(i.value="hidden",H(c),S()))})))}return C(()=>{le([v],(o,E,p)=>{te(p),I.value=!1},{immediate:!0})}),B(N,P),ue(w(()=>O(i.value,{["visible"]:u.Open,["hidden"]:u.Closed})|n.value)),()=>{let{appear:o,show:E,enter:p,enterFrom:V,enterTo:Ce,entered:ye,leave:be,leaveFrom:Ee,leaveTo:Ve,...U}=e,ne={ref:d},re={...U,...A.value&&v.value&&fe.isServer?{class:ae([a.class,U.class,...j,...M])}:{}};return q({theirProps:re,ourProps:ne,slot:{},slots:s,attrs:a,features:W,visible:i.value==="visible",name:"TransitionChild"})}}}),ce=he,Se=K({inheritAttrs:!1,props:{as:{type:[Object,String],default:"div"},show:{type:[Boolean],default:null},unmount:{type:[Boolean],default:!0},appear:{type:[Boolean],default:!1},enter:{type:[String],default:""},enterFrom:{type:[String],default:""},enterTo:{type:[String],default:""},entered:{type:[String],default:""},leave:{type:[String],default:""},leaveFrom:{type:[String],default:""},leaveTo:{type:[String],default:""}},emits:{beforeEnter:()=>!0,afterEnter:()=>!0,beforeLeave:()=>!0,afterLeave:()=>!0},setup(e,{emit:t,attrs:a,slots:s}){let h=oe(),n=w(()=>e.show===null&&h!==null?(h.value&u.Open)===u.Open:e.show);x(()=>{if(![!0,!1].includes(n.value))throw new Error('A <Transition /> is used but it is missing a `:show="true | false"` prop.')});let r=m(n.value?"visible":"hidden"),l=Q(()=>{r.value="hidden"}),f=m(!0),S={show:n,appear:w(()=>e.appear||!f.value)};return C(()=>{x(()=>{f.value=!1,n.value?r.value="visible":L(l)||(r.value="hidden")})}),B(N,l),B(R,S),()=>{let d=ve(e,["show","appear","unmount","onBeforeEnter","onBeforeLeave","onAfterEnter","onAfterLeave"]),y={unmount:e.unmount};return q({ourProps:{...y,as:"template"},theirProps:{},slot:{},slots:{...s,default:()=>[k(ce,{onBeforeEnter:()=>t("beforeEnter"),onAfterEnter:()=>t("afterEnter"),onBeforeLeave:()=>t("beforeLeave"),onAfterLeave:()=>t("afterLeave"),...a,...y,...d},s.default)]},attrs:{},features:W,visible:r.value==="visible",name:"Transition"})}}});export{he as TransitionChild,Se as TransitionRoot}; | ||
import{computed as w,defineComponent as K,h as k,inject as F,normalizeClass as ae,onMounted as C,onUnmounted as z,provide as B,ref as m,watch as le,watchEffect as x}from"vue";import{useId as ie}from'../../hooks/use-id.js';import{State as u,hasOpenClosed as se,useOpenClosed as oe,useOpenClosedProvider as ue}from'../../internal/open-closed.js';import{dom as $}from'../../utils/dom.js';import{env as fe}from'../../utils/env.js';import{match as O}from'../../utils/match.js';import{Features as de,RenderStrategy as T,omit as ve,render as q}from'../../utils/render.js';import{Reason as G,transition as J}from'./utils/transition.js';function g(e=""){return e.split(/\s+/).filter(t=>t.length>1)}let R=Symbol("TransitionContext");var pe=(a=>(a.Visible="visible",a.Hidden="hidden",a))(pe||{});function me(){return F(R,null)!==null}function Te(){let e=F(R,null);if(e===null)throw new Error("A <TransitionChild /> is used but it is missing a parent <TransitionRoot />.");return e}function ge(){let e=F(N,null);if(e===null)throw new Error("A <TransitionChild /> is used but it is missing a parent <TransitionRoot />.");return e}let N=Symbol("NestingContext");function L(e){return"children"in e?L(e.children):e.value.filter(({state:t})=>t==="visible").length>0}function Q(e){let t=m([]),a=m(!1);C(()=>a.value=!0),z(()=>a.value=!1);function s(n,r=T.Hidden){let l=t.value.findIndex(({id:f})=>f===n);l!==-1&&(O(r,{[T.Unmount](){t.value.splice(l,1)},[T.Hidden](){t.value[l].state="hidden"}}),!L(t)&&a.value&&(e==null||e()))}function h(n){let r=t.value.find(({id:l})=>l===n);return r?r.state!=="visible"&&(r.state="visible"):t.value.push({id:n,state:"visible"}),()=>s(n,T.Unmount)}return{children:t,register:h,unregister:s}}let W=de.RenderStrategy,he=K({props:{as:{type:[Object,String],default:"div"},show:{type:[Boolean],default:null},unmount:{type:[Boolean],default:!0},appear:{type:[Boolean],default:!1},enter:{type:[String],default:""},enterFrom:{type:[String],default:""},enterTo:{type:[String],default:""},entered:{type:[String],default:""},leave:{type:[String],default:""},leaveFrom:{type:[String],default:""},leaveTo:{type:[String],default:""}},emits:{beforeEnter:()=>!0,afterEnter:()=>!0,beforeLeave:()=>!0,afterLeave:()=>!0},setup(e,{emit:t,attrs:a,slots:s,expose:h}){let n=m(0);function r(){n.value|=u.Opening,t("beforeEnter")}function l(){n.value&=~u.Opening,t("afterEnter")}function f(){n.value|=u.Closing,t("beforeLeave")}function S(){n.value&=~u.Closing,t("afterLeave")}if(!me()&&se())return()=>k(Se,{...e,onBeforeEnter:r,onAfterEnter:l,onBeforeLeave:f,onAfterLeave:S},s);let d=m(null),y=w(()=>e.unmount?T.Unmount:T.Hidden);h({el:d,$el:d});let{show:v,appear:A}=Te(),{register:D,unregister:H}=ge(),i=m(v.value?"visible":"hidden"),I={value:!0},c=ie(),b={value:!1},P=Q(()=>{!b.value&&i.value!=="hidden"&&(i.value="hidden",H(c),S())});C(()=>{let o=D(c);z(o)}),x(()=>{if(y.value===T.Hidden&&c){if(v.value&&i.value!=="visible"){i.value="visible";return}O(i.value,{["hidden"]:()=>H(c),["visible"]:()=>D(c)})}});let j=g(e.enter),M=g(e.enterFrom),X=g(e.enterTo),_=g(e.entered),Y=g(e.leave),Z=g(e.leaveFrom),ee=g(e.leaveTo);C(()=>{x(()=>{if(i.value==="visible"){let o=$(d);if(o instanceof Comment&&o.data==="")throw new Error("Did you forget to passthrough the `ref` to the actual DOM node?")}})});function te(o){let E=I.value&&!A.value,p=$(d);!p||!(p instanceof HTMLElement)||E||(b.value=!0,v.value&&r(),v.value||f(),o(v.value?J(p,j,M,X,_,V=>{b.value=!1,V===G.Finished&&l()}):J(p,Y,Z,ee,_,V=>{b.value=!1,V===G.Finished&&(L(P)||(i.value="hidden",H(c),S()))})))}return C(()=>{le([v],(o,E,p)=>{te(p),I.value=!1},{immediate:!0})}),B(N,P),ue(w(()=>O(i.value,{["visible"]:u.Open,["hidden"]:u.Closed})|n.value)),()=>{let{appear:o,show:E,enter:p,enterFrom:V,enterTo:Ce,entered:ye,leave:be,leaveFrom:Ee,leaveTo:Ve,...U}=e,ne={ref:d},re={...U,...A.value&&v.value&&fe.isServer?{class:ae([a.class,U.class,...j,...M])}:{}};return q({theirProps:re,ourProps:ne,slot:{},slots:s,attrs:a,features:W,visible:i.value==="visible",name:"TransitionChild"})}}}),ce=he,Se=K({inheritAttrs:!1,props:{as:{type:[Object,String],default:"div"},show:{type:[Boolean],default:null},unmount:{type:[Boolean],default:!0},appear:{type:[Boolean],default:!1},enter:{type:[String],default:""},enterFrom:{type:[String],default:""},enterTo:{type:[String],default:""},entered:{type:[String],default:""},leave:{type:[String],default:""},leaveFrom:{type:[String],default:""},leaveTo:{type:[String],default:""}},emits:{beforeEnter:()=>!0,afterEnter:()=>!0,beforeLeave:()=>!0,afterLeave:()=>!0},setup(e,{emit:t,attrs:a,slots:s}){let h=oe(),n=w(()=>e.show===null&&h!==null?(h.value&u.Open)===u.Open:e.show);x(()=>{if(![!0,!1].includes(n.value))throw new Error('A <Transition /> is used but it is missing a `:show="true | false"` prop.')});let r=m(n.value?"visible":"hidden"),l=Q(()=>{r.value="hidden"}),f=m(!0),S={show:n,appear:w(()=>e.appear||!f.value)};return C(()=>{x(()=>{f.value=!1,n.value?r.value="visible":L(l)||(r.value="hidden")})}),B(N,l),B(R,S),()=>{let d=ve(e,["show","appear","unmount","onBeforeEnter","onBeforeLeave","onAfterEnter","onAfterLeave"]),y={unmount:e.unmount};return q({ourProps:{...y,as:"template"},theirProps:{},slot:{},slots:{...s,default:()=>[k(ce,{onBeforeEnter:()=>t("beforeEnter"),onAfterEnter:()=>t("afterEnter"),onBeforeLeave:()=>t("beforeLeave"),onAfterLeave:()=>t("afterLeave"),...a,...y,...d},s.default)]},attrs:{},features:W,visible:r.value==="visible",name:"Transition"})}}});export{he as TransitionChild,Se as TransitionRoot}; |
@@ -1,2 +0,2 @@ | ||
import { ScrollLockStep } from './overflow-store.js'; | ||
import type { ScrollLockStep } from './overflow-store.js'; | ||
export declare function adjustScrollbarPadding(): ScrollLockStep; |
@@ -1,1 +0,1 @@ | ||
function c(){let o;return{before({doc:e}){var l;let n=e.documentElement;o=((l=e.defaultView)!=null?l:window).innerWidth-n.clientWidth},after({doc:e,d:n}){let t=e.documentElement,l=t.clientWidth-t.offsetWidth,r=o-l;n.style(t,"paddingRight",`${r}px`)}}}export{c as adjustScrollbarPadding}; | ||
function d(){let r;return{before({doc:e}){var l;let o=e.documentElement,t=(l=e.defaultView)!=null?l:window;r=Math.max(0,t.innerWidth-o.clientWidth)},after({doc:e,d:o}){let t=e.documentElement,l=Math.max(0,t.clientWidth-t.offsetWidth),n=Math.max(0,r-l);o.style(t,"paddingRight",`${n}px`)}}}export{d as adjustScrollbarPadding}; |
@@ -1,2 +0,2 @@ | ||
import { ScrollLockStep } from './overflow-store.js'; | ||
import type { ScrollLockStep } from './overflow-store.js'; | ||
interface ContainerMetadata { | ||
@@ -3,0 +3,0 @@ containers: (() => HTMLElement[])[]; |
@@ -1,1 +0,1 @@ | ||
import{disposables as f}from'../../utils/disposables.js';import{isIOS as m}from'../../utils/platform.js';function w(){if(!m())return{};let r;return{before(){r=window.pageYOffset},after({doc:n,d:o,meta:s}){function i(e){return s.containers.flatMap(t=>t()).some(t=>t.contains(e))}if(window.getComputedStyle(n.documentElement).scrollBehavior!=="auto"){let e=f();e.style(n.documentElement,"scroll-behavior","auto"),o.add(()=>o.microTask(()=>e.dispose()))}o.style(n.body,"marginTop",`-${r}px`),window.scrollTo(0,0);let l=null;o.addEventListener(n,"click",e=>{if(e.target instanceof HTMLElement)try{let t=e.target.closest("a");if(!t)return;let{hash:c}=new URL(t.href),a=n.querySelector(c);a&&!i(a)&&(l=a)}catch{}},!0),o.addEventListener(n,"touchmove",e=>{e.target instanceof HTMLElement&&!i(e.target)&&e.preventDefault()},{passive:!1}),o.add(()=>{window.scrollTo(0,window.pageYOffset+r),l&&l.isConnected&&(l.scrollIntoView({block:"nearest"}),l=null)})}}}export{w 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,2 +0,2 @@ | ||
import { Disposables } from '../../utils/disposables.js'; | ||
import { type Disposables } from '../../utils/disposables.js'; | ||
interface DocEntry { | ||
@@ -3,0 +3,0 @@ doc: Document; |
@@ -1,2 +0,2 @@ | ||
import { ScrollLockStep } from './overflow-store.js'; | ||
import type { ScrollLockStep } from './overflow-store.js'; | ||
export declare function preventScroll(): ScrollLockStep; |
@@ -1,1 +0,1 @@ | ||
function l(){return{before({doc:e,d:o}){o.style(e.documentElement,"overflow","hidden")}}}export{l as preventScroll}; | ||
function r(){return{before({doc:e,d:o}){o.style(e.documentElement,"overflow","hidden")}}}export{r as preventScroll}; |
@@ -1,3 +0,3 @@ | ||
import { Ref } from 'vue'; | ||
import { MetaFn } from './overflow-store.js'; | ||
import { type Ref } from 'vue'; | ||
import { type MetaFn } from './overflow-store.js'; | ||
export declare function useDocumentOverflowLockedEffect(doc: Ref<Document | null>, shouldBeLocked: Ref<boolean>, meta: MetaFn): import("vue").ComputedRef<boolean>; |
@@ -1,1 +0,1 @@ | ||
import{computed as p,watch as s}from"vue";import{useStore as v}from'../../hooks/use-store.js';import{overflows as u}from'./overflow-store.js';function d(t,a,n){let i=v(u),l=p(()=>{let e=t.value?i.value.get(t.value):void 0;return e?e.count>0:!1});return s([t,a],([e,m],[r],o)=>{if(!e||!m)return;u.dispatch("PUSH",e,n);let f=!1;o(()=>{f||(u.dispatch("POP",r!=null?r:e,n),f=!0)})},{immediate:!0}),l}export{d as useDocumentOverflowLockedEffect}; | ||
import{computed as o,watch as s}from"vue";import{useStore as v}from'../../hooks/use-store.js';import{overflows as u}from'./overflow-store.js';function w(t,a,n){let i=v(u),l=o(()=>{let e=t.value?i.value.get(t.value):void 0;return e?e.count>0:!1});return s([t,a],([e,m],[r],p)=>{if(!e||!m)return;u.dispatch("PUSH",e,n);let f=!1;p(()=>{f||(u.dispatch("POP",r!=null?r:e,n),f=!0)})},{immediate:!0}),l}export{w as useDocumentOverflowLockedEffect}; |
@@ -1,2 +0,2 @@ | ||
import { ComputedRef, UnwrapRef } from 'vue'; | ||
import { type ComputedRef, type UnwrapRef } from 'vue'; | ||
export declare function useControllable<T>(controlledValue: ComputedRef<T | undefined>, onChange?: (value: T) => void, defaultValue?: ComputedRef<T>): readonly [ComputedRef<T | UnwrapRef<T> | undefined>, (value: unknown) => void | undefined]; |
@@ -1,1 +0,1 @@ | ||
import{computed as p,ref as s}from"vue";function d(u,e,r){let i=s(r==null?void 0:r.value),f=p(()=>u.value!==void 0);return[p(()=>f.value?u.value:i.value),function(t){return f.value||(i.value=t),e==null?void 0:e(t)}]}export{d as useControllable}; | ||
import{computed as f,ref as s}from"vue";function T(u,e,r){let p=s(r==null?void 0:r.value),i=f(()=>u.value!==void 0);return[f(()=>i.value?u.value:p.value),function(t){return i.value||(p.value=t),e==null?void 0:e(t)}]}export{T as useControllable}; |
@@ -1,1 +0,2 @@ | ||
export declare function useDocumentEvent<TType extends keyof DocumentEventMap>(type: TType, listener: (this: Document, ev: DocumentEventMap[TType]) => any, options?: boolean | AddEventListenerOptions): void; | ||
import { type Ref } from 'vue'; | ||
export declare function useDocumentEvent<TType extends keyof DocumentEventMap>(enabled: Ref<boolean>, type: TType, listener: (this: Document, ev: DocumentEventMap[TType]) => any, options?: boolean | AddEventListenerOptions): void; |
@@ -1,1 +0,1 @@ | ||
import{watchEffect as r}from"vue";import{env as m}from'../utils/env.js';function u(e,t,n){m.isServer||r(o=>{document.addEventListener(e,t,n),o(()=>document.removeEventListener(e,t,n))})}export{u as useDocumentEvent}; | ||
import{watchEffect as m}from"vue";import{env as u}from'../utils/env.js';function c(o,e,t,n){u.isServer||m(r=>{o.value&&(document.addEventListener(e,t,n),r(()=>document.removeEventListener(e,t,n)))})}export{c as useDocumentEvent}; |
@@ -1,2 +0,2 @@ | ||
import { Ref } from 'vue'; | ||
import { type Ref } from 'vue'; | ||
export declare function useInert<TElement extends HTMLElement>(node: Ref<TElement | null>, enabled?: Ref<boolean>): void; |
@@ -1,1 +0,1 @@ | ||
import{ref as m,watchEffect as s}from"vue";import{dom as h}from'../utils/dom.js';let i=new Map,t=new Map;function E(d,f=m(!0)){s(o=>{var a;if(!f.value)return;let e=h(d);if(!e)return;o(function(){var u;if(!e)return;let r=(u=t.get(e))!=null?u:1;if(r===1?t.delete(e):t.set(e,r-1),r!==1)return;let n=i.get(e);n&&(n["aria-hidden"]===null?e.removeAttribute("aria-hidden"):e.setAttribute("aria-hidden",n["aria-hidden"]),e.inert=n.inert,i.delete(e))});let l=(a=t.get(e))!=null?a:0;t.set(e,l+1),l===0&&(i.set(e,{"aria-hidden":e.getAttribute("aria-hidden"),inert:e.inert}),e.setAttribute("aria-hidden","true"),e.inert=!0)})}export{E as useInert}; | ||
import{ref as m,watchEffect as s}from"vue";import{dom as h}from'../utils/dom.js';let i=new Map,t=new Map;function p(d,f=m(!0)){s(o=>{var a;if(!f.value)return;let e=h(d);if(!e)return;o(function(){var u;if(!e)return;let r=(u=t.get(e))!=null?u:1;if(r===1?t.delete(e):t.set(e,r-1),r!==1)return;let n=i.get(e);n&&(n["aria-hidden"]===null?e.removeAttribute("aria-hidden"):e.setAttribute("aria-hidden",n["aria-hidden"]),e.inert=n.inert,i.delete(e))});let l=(a=t.get(e))!=null?a:0;t.set(e,l+1),l===0&&(i.set(e,{"aria-hidden":e.getAttribute("aria-hidden"),inert:e.inert}),e.setAttribute("aria-hidden","true"),e.inert=!0)})}export{p as useInert}; |
@@ -1,1 +0,1 @@ | ||
import{computed as s,ref as E}from"vue";import{dom as p}from'../utils/dom.js';import{FocusableMode as d,isFocusableElement as C}from'../utils/focus-management.js';import{isMobile as T}from'../utils/platform.js';import{useDocumentEvent as i}from'./use-document-event.js';import{useWindowEvent as M}from'./use-window-event.js';function w(f,m,l=s(()=>!0)){function a(e,r){if(!l.value||e.defaultPrevented)return;let t=r(e);if(t===null||!t.getRootNode().contains(t))return;let c=function o(n){return typeof n=="function"?o(n()):Array.isArray(n)||n instanceof Set?n:[n]}(f);for(let o of c){if(o===null)continue;let n=o instanceof HTMLElement?o:p(o);if(n!=null&&n.contains(t)||e.composed&&e.composedPath().includes(n))return}return!C(t,d.Loose)&&t.tabIndex!==-1&&e.preventDefault(),m(e,t)}let u=E(null);i("pointerdown",e=>{var r,t;l.value&&(u.value=((t=(r=e.composedPath)==null?void 0:r.call(e))==null?void 0:t[0])||e.target)},!0),i("mousedown",e=>{var r,t;l.value&&(u.value=((t=(r=e.composedPath)==null?void 0:r.call(e))==null?void 0:t[0])||e.target)},!0),i("click",e=>{T()||u.value&&(a(e,()=>u.value),u.value=null)},!0),i("touchend",e=>a(e,()=>e.target instanceof HTMLElement?e.target:null),!0),M("blur",e=>a(e,()=>window.document.activeElement instanceof HTMLIFrameElement?window.document.activeElement:null),!0)}export{w as useOutsideClick}; | ||
import{computed as p,ref as d}from"vue";import{dom as C}from'../utils/dom.js';import{FocusableMode as h,isFocusableElement as T}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 y}from'./use-window-event.js';const f=30;function R(s,m,r=p(()=>!0)){function c(t,o){if(t.defaultPrevented)return;let e=o(t);if(e===null||!e.getRootNode().contains(e))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:C(u);if(n!=null&&n.contains(e)||t.composed&&t.composedPath().includes(n))return}return!T(e,h.Loose)&&e.tabIndex!==-1&&t.preventDefault(),m(t,e)}let i=d(null);l(r,"pointerdown",t=>{var o,e;i.value=((e=(o=t.composedPath)==null?void 0:o.call(t))==null?void 0:e[0])||t.target},!0),l(r,"mousedown",t=>{var o,e;i.value=((e=(o=t.composedPath)==null?void 0:o.call(t))==null?void 0:e[0])||t.target},!0),l(r,"click",t=>{M()||i.value&&(c(t,()=>i.value),i.value=null)},!0);let a={x:0,y:0};l(r,"touchstart",t=>{a.x=t.touches[0].clientX,a.y=t.touches[0].clientY},!0),l(r,"touchend",t=>{let o={x:t.changedTouches[0].clientX,y:t.changedTouches[0].clientY};if(!(Math.abs(o.x-a.x)>=f||Math.abs(o.y-a.y)>=f))return c(t,()=>t.target instanceof HTMLElement?t.target:null)},!0),y(r,"blur",t=>c(t,()=>window.document.activeElement instanceof HTMLIFrameElement?window.document.activeElement:null),!0)}export{R as useOutsideClick}; |
@@ -1,1 +0,1 @@ | ||
import{h as f,ref as a}from"vue";import{Features as m,Hidden as d}from'../internal/hidden.js';import{dom as T}from'../utils/dom.js';import{getOwnerDocument as H}from'../utils/owner.js';function R({defaultContainers:t=[],portals:o,mainTreeNodeRef:s}={}){let i=a(null),r=H(i);function u(){var l;let n=[];for(let e of t)e!==null&&(e instanceof HTMLElement?n.push(e):"value"in e&&e.value instanceof HTMLElement&&n.push(e.value));if(o!=null&&o.value)for(let e of o.value)n.push(e);for(let e of(l=r==null?void 0:r.querySelectorAll("html > *, body > *"))!=null?l:[])e!==document.body&&e!==document.head&&e instanceof HTMLElement&&e.id!=="headlessui-portal-root"&&(e.contains(T(i))||n.some(c=>e.contains(c))||n.push(e));return n}return{resolveContainers:u,contains(n){return u().some(l=>l.contains(n))},mainTreeNodeRef:i,MainTreeNode(){return s!=null?null:f(d,{features:m.Hidden,ref:i})}}}function h(){let t=a(null);return{mainTreeNodeRef:t,MainTreeNode(){return f(d,{features:m.Hidden,ref:t})}}}export{h as useMainTreeNode,R as useRootContainers}; | ||
import{h as m,ref as s}from"vue";import{Hidden as d,Features as c}from'../internal/hidden.js';import{dom as T}from'../utils/dom.js';import{getOwnerDocument as E}from'../utils/owner.js';function N({defaultContainers:o=[],portals:i,mainTreeNodeRef:H}={}){let t=s(null),r=E(t);function u(){var l,f,a;let n=[];for(let e of o)e!==null&&(e instanceof HTMLElement?n.push(e):"value"in e&&e.value instanceof HTMLElement&&n.push(e.value));if(i!=null&&i.value)for(let e of i.value)n.push(e);for(let e of(l=r==null?void 0:r.querySelectorAll("html > *, body > *"))!=null?l:[])e!==document.body&&e!==document.head&&e instanceof HTMLElement&&e.id!=="headlessui-portal-root"&&(e.contains(T(t))||e.contains((a=(f=T(t))==null?void 0:f.getRootNode())==null?void 0:a.host)||n.some(M=>e.contains(M))||n.push(e));return n}return{resolveContainers:u,contains(n){return u().some(l=>l.contains(n))},mainTreeNodeRef:t,MainTreeNode(){return H!=null?null:m(d,{features:c.Hidden,ref:t})}}}function v(){let o=s(null);return{mainTreeNodeRef:o,MainTreeNode(){return m(d,{features:c.Hidden,ref:o})}}}export{v as useMainTreeNode,N as useRootContainers}; |
@@ -1,2 +0,2 @@ | ||
import { Store } from '../utils/store.js'; | ||
import type { Store } from '../utils/store.js'; | ||
export declare function useStore<T>(store: Store<T, any>): import("vue").ShallowRef<T>; |
@@ -1,1 +0,1 @@ | ||
import{onUnmounted as o,shallowRef as n}from"vue";function m(t){let e=n(t.getSnapshot());return o(t.subscribe(()=>{e.value=t.getSnapshot()})),e}export{m as useStore}; | ||
import{onUnmounted as o,shallowRef as r}from"vue";function s(t){let e=r(t.getSnapshot());return o(t.subscribe(()=>{e.value=t.getSnapshot()})),e}export{s as useStore}; |
@@ -1,1 +0,1 @@ | ||
import{ref as a}from"vue";import{useWindowEvent as t}from'./use-window-event.js';var d=(r=>(r[r.Forwards=0]="Forwards",r[r.Backwards=1]="Backwards",r))(d||{});function n(){let o=a(0);return t("keydown",e=>{e.key==="Tab"&&(o.value=e.shiftKey?1:0)}),o}export{d as Direction,n as useTabDirection}; | ||
import{ref as o}from"vue";import{useWindowEvent as t}from'./use-window-event.js';var d=(r=>(r[r.Forwards=0]="Forwards",r[r.Backwards=1]="Backwards",r))(d||{});function s(){let e=o(0),a=o(!0);return t(a,"keydown",r=>{r.key==="Tab"&&(e.value=r.shiftKey?1:0)}),e}export{d as Direction,s as useTabDirection}; |
@@ -1,2 +0,2 @@ | ||
import { Ref } from 'vue'; | ||
import { type Ref } from 'vue'; | ||
export declare function useTextValue(element: Ref<HTMLElement | null>): () => string; |
@@ -1,1 +0,2 @@ | ||
export declare function useWindowEvent<TType extends keyof WindowEventMap>(type: TType, listener: (this: Window, ev: WindowEventMap[TType]) => any, options?: boolean | AddEventListenerOptions): void; | ||
import { type Ref } from 'vue'; | ||
export declare function useWindowEvent<TType extends keyof WindowEventMap>(enabled: Ref<boolean>, type: TType, listener: (this: Window, ev: WindowEventMap[TType]) => any, options?: boolean | AddEventListenerOptions): void; |
@@ -1,1 +0,1 @@ | ||
import{watchEffect as i}from"vue";import{env as r}from'../utils/env.js';function w(e,n,t){r.isServer||i(o=>{window.addEventListener(e,n,t),o(()=>window.removeEventListener(e,n,t))})}export{w as useWindowEvent}; | ||
import{watchEffect as r}from"vue";import{env as d}from'../utils/env.js';function w(o,e,n,t){d.isServer||r(i=>{o.value&&(window.addEventListener(e,n,t),i(()=>window.removeEventListener(e,n,t)))})}export{w as useWindowEvent}; |
@@ -1,1 +0,1 @@ |
import{defineComponent as a}from"vue";import{render as p}from'../utils/render.js';var s=(e=>(e[e.None=1]="None",e[e.Focusable=2]="Focusable",e[e.Hidden=4]="Hidden",e))(s||{});let f=a({name:"Hidden",props:{as:{type:[Object,String],default:"div"},features:{type:Number,default:1}},setup(d,{slots:o,attrs:i}){return()=>{var t;let{features:e,...r}=d,n={"aria-hidden":(e&2)===2?!0:(t=r["aria-hidden"])!=null?t: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",...(e&4)===4&&(e&2)!==2&&{display:"none"}}};return p({ourProps:n,theirProps:r,slot:{},attrs:i,slots:o,name:"Hidden"})}}});export{s as Features,f as Hidden}; |
import{defineComponent as a}from"vue";import{render as p}from'../utils/render.js';var u=(e=>(e[e.None=1]="None",e[e.Focusable=2]="Focusable",e[e.Hidden=4]="Hidden",e))(u||{});let f=a({name:"Hidden",props:{as:{type:[Object,String],default:"div"},features:{type:Number,default:1}},setup(t,{slots:n,attrs:i}){return()=>{var r;let{features:e,...d}=t,o={"aria-hidden":(e&2)===2?!0:(r=d["aria-hidden"])!=null?r:void 0,hidden:(e&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",...(e&4)===4&&(e&2)!==2&&{display:"none"}}};return p({ourProps:o,theirProps:d,slot:{},attrs:i,slots:n,name:"Hidden"})}}});export{u as Features,f as Hidden}; |
@@ -23,4 +23,4 @@ export declare enum Focus { | ||
resolveActiveIndex(): number | null; | ||
resolveId(item: TItem): string; | ||
resolveDisabled(item: TItem): boolean; | ||
resolveId(item: TItem, index: number, items: TItem[]): string; | ||
resolveDisabled(item: TItem, index: number, items: TItem[]): boolean; | ||
}): number | null; |
@@ -1,1 +0,1 @@ | ||
function f(r){throw new Error("Unexpected object: "+r)}var a=(e=>(e[e.First=0]="First",e[e.Previous=1]="Previous",e[e.Next=2]="Next",e[e.Last=3]="Last",e[e.Specific=4]="Specific",e[e.Nothing=5]="Nothing",e))(a||{});function x(r,n){let t=n.resolveItems();if(t.length<=0)return null;let l=n.resolveActiveIndex(),s=l!=null?l:-1,d=(()=>{switch(r.focus){case 0:return t.findIndex(e=>!n.resolveDisabled(e));case 1:{let e=t.slice().reverse().findIndex((i,c,u)=>s!==-1&&u.length-c-1>=s?!1:!n.resolveDisabled(i));return e===-1?e:t.length-1-e}case 2:return t.findIndex((e,i)=>i<=s?!1:!n.resolveDisabled(e));case 3:{let e=t.slice().reverse().findIndex(i=>!n.resolveDisabled(i));return e===-1?e:t.length-1-e}case 4:return t.findIndex(e=>n.resolveId(e)===r.id);case 5:return null;default:f(r)}})();return d===-1?l:d}export{a as Focus,x as calculateActiveIndex}; | ||
function u(l){throw new Error("Unexpected object: "+l)}var c=(i=>(i[i.First=0]="First",i[i.Previous=1]="Previous",i[i.Next=2]="Next",i[i.Last=3]="Last",i[i.Specific=4]="Specific",i[i.Nothing=5]="Nothing",i))(c||{});function f(l,n){let t=n.resolveItems();if(t.length<=0)return null;let r=n.resolveActiveIndex(),s=r!=null?r:-1;switch(l.focus){case 0:{for(let e=0;e<t.length;++e)if(!n.resolveDisabled(t[e],e,t))return e;return r}case 1:{s===-1&&(s=t.length);for(let e=s-1;e>=0;--e)if(!n.resolveDisabled(t[e],e,t))return e;return r}case 2:{for(let e=s+1;e<t.length;++e)if(!n.resolveDisabled(t[e],e,t))return e;return r}case 3:{for(let e=t.length-1;e>=0;--e)if(!n.resolveDisabled(t[e],e,t))return e;return r}case 4:{for(let e=0;e<t.length;++e)if(n.resolveId(t[e],e,t)===l.id)return e;return r}case 5:return null;default:u(l)}}export{c as Focus,f as calculateActiveIndex}; |
@@ -1,4 +0,4 @@ | ||
import { ComponentPublicInstance, Ref } from 'vue'; | ||
import type { ComponentPublicInstance, Ref } from 'vue'; | ||
type AsElement<T extends HTMLElement | ComponentPublicInstance> = (T extends HTMLElement ? T : HTMLElement) | null; | ||
export declare function dom<T extends HTMLElement | ComponentPublicInstance>(ref?: Ref<T | null>): AsElement<T> | null; | ||
export {}; |
@@ -1,1 +0,1 @@ | ||
function o(e){var l;if(e==null||e.value==null)return null;let n=(l=e.value.$el)!=null?l:e.value;return n instanceof Node?n:null}export{o as dom}; | ||
function t(e){var l;if(e==null||e.value==null)return null;let n=(l=e.value.$el)!=null?l:e.value;return n instanceof Node?n:null}export{t as dom}; |
@@ -1,2 +0,2 @@ | ||
import { type Ref } from 'vue'; | ||
export declare function getOwnerDocument<T extends Element | Ref<Element | null>>(element: T | null | undefined): Document | null; | ||
import type { Ref } from 'vue'; | ||
export declare function getOwnerDocument<T extends HTMLElement | Ref<HTMLElement | null>>(element: T | null | undefined): Document | null; |
@@ -1,1 +0,1 @@ | ||
import{dom as o}from'./dom.js';import{env as t}from'./env.js';function i(r){if(t.isServer)return null;if(r instanceof Node)return r.ownerDocument;if(r!=null&&r.hasOwnProperty("value")){let n=o(r);if(n)return n.ownerDocument}return document}export{i as getOwnerDocument}; | ||
import{dom as o}from'./dom.js';import{env as t}from'./env.js';function f(r){if(t.isServer)return null;if(r instanceof Node)return r.ownerDocument;if(r!=null&&r.hasOwnProperty("value")){let n=o(r);if(n)return n.ownerDocument}return document}export{f as getOwnerDocument}; |
import{cloneVNode as O,Fragment as x,h as k}from"vue";import{match as w}from'./match.js';var N=(o=>(o[o.None=0]="None",o[o.RenderStrategy=1]="RenderStrategy",o[o.Static=2]="Static",o))(N||{}),S=(e=>(e[e.Unmount=0]="Unmount",e[e.Hidden=1]="Hidden",e))(S||{});function A({visible:r=!0,features:t=0,ourProps:e,theirProps:o,...i}){var a;let n=j(o,e),l=Object.assign(i,{props:n});if(r||t&2&&n.static)return y(l);if(t&1){let d=(a=n.unmount)==null||a?0:1;return w(d,{[0](){return null},[1](){return y({...i,props:{...n,hidden:!0,style:{display:"none"}}})}})}return y(l)}function y({props:r,attrs:t,slots:e,slot:o,name:i}){var m,h;let{as:n,...l}=T(r,["unmount","static"]),a=(m=e.default)==null?void 0:m.call(e,o),d={};if(o){let u=!1,c=[];for(let[p,f]of Object.entries(o))typeof f=="boolean"&&(u=!0),f===!0&&c.push(p);u&&(d["data-headlessui-state"]=c.join(" "))}if(n==="template"){if(a=b(a!=null?a:[]),Object.keys(l).length>0||Object.keys(t).length>0){let[u,...c]=a!=null?a:[];if(!v(u)||c.length>0)throw new Error(['Passing props on "template"!',"",`The current component <${i} /> is rendering a "template".`,"However we need to passthrough the following props:",Object.keys(l).concat(Object.keys(t)).map(s=>s.trim()).filter((s,g,R)=>R.indexOf(s)===g).sort((s,g)=>s.localeCompare(g)).map(s=>` - ${s}`).join(` | ||
`),"","You can apply a few solutions:",['Add an `as="..."` prop, to ensure that we render an actual element instead of a "template".',"Render a single element as the child so that we can forward the props onto that element."].map(s=>` - ${s}`).join(` | ||
`)].join(` | ||
`));let p=j((h=u.props)!=null?h:{},l),f=O(u,p,!0);for(let s in p)s.startsWith("on")&&(f.props||(f.props={}),f.props[s]=p[s]);return f}return Array.isArray(a)&&a.length===1?a[0]:a}return k(n,Object.assign({},l,d),{default:()=>a})}function b(r){return r.flatMap(t=>t.type===x?b(t.children):[t])}function j(...r){var o;if(r.length===0)return{};if(r.length===1)return r[0];let t={},e={};for(let i of r)for(let n in i)n.startsWith("on")&&typeof i[n]=="function"?((o=e[n])!=null||(e[n]=[]),e[n].push(i[n])):t[n]=i[n];if(t.disabled||t["aria-disabled"])return Object.assign(t,Object.fromEntries(Object.keys(e).map(i=>[i,void 0])));for(let i in e)Object.assign(t,{[i](n,...l){let a=e[i];for(let d of a){if(n instanceof Event&&n.defaultPrevented)return;d(n,...l)}}});return t}function E(r){let t=Object.assign({},r);for(let e in t)t[e]===void 0&&delete t[e];return t}function T(r,t=[]){let e=Object.assign({},r);for(let o of t)o in e&&delete e[o];return e}function v(r){return r==null?!1:typeof r.type=="string"||typeof r.type=="object"||typeof r.type=="function"}export{N as Features,S as RenderStrategy,E as compact,T as omit,A as render}; | ||
`));let p=j((h=u.props)!=null?h:{},l,d),f=O(u,p,!0);for(let s in p)s.startsWith("on")&&(f.props||(f.props={}),f.props[s]=p[s]);return f}return Array.isArray(a)&&a.length===1?a[0]:a}return k(n,Object.assign({},l,d),{default:()=>a})}function b(r){return r.flatMap(t=>t.type===x?b(t.children):[t])}function j(...r){var o;if(r.length===0)return{};if(r.length===1)return r[0];let t={},e={};for(let i of r)for(let n in i)n.startsWith("on")&&typeof i[n]=="function"?((o=e[n])!=null||(e[n]=[]),e[n].push(i[n])):t[n]=i[n];if(t.disabled||t["aria-disabled"])return Object.assign(t,Object.fromEntries(Object.keys(e).map(i=>[i,void 0])));for(let i in e)Object.assign(t,{[i](n,...l){let a=e[i];for(let d of a){if(n instanceof Event&&n.defaultPrevented)return;d(n,...l)}}});return t}function E(r){let t=Object.assign({},r);for(let e in t)t[e]===void 0&&delete t[e];return t}function T(r,t=[]){let e=Object.assign({},r);for(let o of t)o in e&&delete e[o];return e}function v(r){return r==null?!1:typeof r.type=="string"||typeof r.type=="object"||typeof r.type=="function"}export{N as Features,S as RenderStrategy,E as compact,T as omit,A as render}; |
{ | ||
"name": "@headlessui/vue", | ||
"version": "0.0.0-insiders.f2179f3", | ||
"version": "0.0.0-insiders.f26cca5", | ||
"description": "A set of completely unstyled, fully accessible UI components for Vue 3, designed to integrate beautifully with Tailwind CSS.", | ||
@@ -14,3 +14,6 @@ "main": "dist/index.cjs", | ||
"exports": { | ||
"types": "./dist/index.d.ts", | ||
"types": { | ||
"import": "./dist/index.d.ts", | ||
"require": "./dist/index.d.cts" | ||
}, | ||
"import": "./dist/headlessui.esm.js", | ||
@@ -38,3 +41,4 @@ "require": "./dist/index.cjs" | ||
"lint": "../../scripts/lint.sh", | ||
"playground": "yarn workspace playground-vue dev", | ||
"lint-types": "npm run attw -P --workspaces --if-present", | ||
"playground": "npm run dev --workspace=playground-vue", | ||
"clean": "rimraf ./dist" | ||
@@ -46,6 +50,9 @@ }, | ||
"devDependencies": { | ||
"@testing-library/vue": "^5.8.2", | ||
"@vue/test-utils": "^2.0.0-rc.18", | ||
"vue": "^3.2.29" | ||
"@testing-library/vue": "8.0.0", | ||
"@vue/test-utils": "^2.4.1", | ||
"vue": "3.2.37" | ||
}, | ||
"dependencies": { | ||
"@tanstack/vue-virtual": "3.0.0-beta.60" | ||
} | ||
} |
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
600984
135
11530
2
4
+ Added@tanstack/virtual-core@3.0.0-beta.60(transitive)
+ Added@tanstack/vue-virtual@3.0.0-beta.60(transitive)