@headlessui/vue
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -502,3 +502,3 @@ 'use strict'; | ||
'aria-expanded': api.menuState.value === MenuStates.Open ? true : undefined, | ||
onKeyDown: this.handleKeyDown, | ||
onKeydown: this.handleKeyDown, | ||
onClick: this.handleClick | ||
@@ -609,3 +609,3 @@ }; | ||
id: this.id, | ||
onKeyDown: this.handleKeyDown, | ||
onKeydown: this.handleKeyDown, | ||
role: 'menu', | ||
@@ -833,6 +833,6 @@ tabIndex: 0, | ||
onFocus: handleFocus, | ||
onPointerMove: handleMove, | ||
onMouseMove: handleMove, | ||
onPointerLeave: handleLeave, | ||
onMouseLeave: handleLeave | ||
onPointermove: handleMove, | ||
onMousemove: handleMove, | ||
onPointerleave: handleLeave, | ||
onMouseleave: handleLeave | ||
}; | ||
@@ -1110,3 +1110,3 @@ return render({ | ||
disabled: api.disabled, | ||
onKeyDown: this.handleKeyDown, | ||
onKeydown: this.handleKeyDown, | ||
onClick: this.handleClick | ||
@@ -1219,3 +1219,3 @@ }; | ||
id: this.id, | ||
onKeyDown: this.handleKeyDown, | ||
onKeydown: this.handleKeyDown, | ||
role: 'listbox', | ||
@@ -1450,6 +1450,6 @@ tabIndex: 0, | ||
onFocus: handleFocus, | ||
onPointerMove: handleMove, | ||
onMouseMove: handleMove, | ||
onPointerLeave: handleLeave, | ||
onMouseLeave: handleLeave | ||
onPointermove: handleMove, | ||
onMousemove: handleMove, | ||
onPointerleave: handleLeave, | ||
onMouseleave: handleLeave | ||
}; | ||
@@ -1554,4 +1554,4 @@ return render({ | ||
onClick: this.handleClick, | ||
onKeyUp: this.handleKeyUp, | ||
onKeyPress: this.handleKeyPress | ||
onKeyup: this.handleKeyUp, | ||
onKeypress: this.handleKeyPress | ||
}; | ||
@@ -1558,0 +1558,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t,n=require("vue");function o(){return(o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e}).apply(this,arguments)}function r(e,t){if(null==e)return{};var n,o,r={},l=Object.keys(e);for(o=0;o<l.length;o++)t.indexOf(n=l[o])>=0||(r[n]=e[n]);return r}function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}function u(e,t){if(e in t){for(var n=t[e],o=arguments.length,r=new Array(o>2?o-2:0),l=2;l<o;l++)r[l-2]=arguments[l];return"function"==typeof n?n.apply(void 0,r):n}var a=new Error('Tried to handle "'+e+'" but there is no handler defined. Only defined handlers are: '+Object.keys(t).map((function(e){return'"'+e+'"'})).join(", ")+".");throw Error.captureStackTrace&&Error.captureStackTrace(a,u),a}function a(n){var l,a,s=n.visible,c=void 0===s||s,d=n.features,v=void 0===d?e.None:d,f=r(n,["visible","features"]);return c||v&e.Static&&f.props.static?i(f):v&e.RenderStrategy?u(null==(l=f.props.unmount)||l?t.Unmount:t.Hidden,((a={})[t.Unmount]=function(){return null},a[t.Hidden]=function(){return i(o({},f,{props:o({},f.props,{hidden:!0,style:{display:"none"}})}))},a)):i(f)}function i(e){var t=e.attrs,o=e.slots,u=e.slot,a=function(e,t){void 0===t&&(t=[]);for(var n,o=Object.assign({},e),r=function(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return l(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?l(e,void 0):void 0}}(e))){n&&(e=n);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}(t);!(n=r()).done;){var u=n.value;u in o&&delete o[u]}return o}(e.props,["unmount","static"]),i=a.as,s=r(a,["as"]),c=null==o.default?void 0:o.default(u);if("template"===i){if(Object.keys(s).length>0||"class"in t){var d=null!=c?c:[],v=d[0];if(d.slice(1).length>0)throw new Error('You should only render 1 child or use the `as="..."` prop');return n.cloneVNode(v,s)}return c}return n.h(i,s,c)}!function(e){e[e.None=0]="None",e[e.RenderStrategy=1]="RenderStrategy",e[e.Static=2]="Static"}(e||(e={})),function(e){e[e.Unmount=0]="Unmount",e[e.Hidden=1]="Hidden"}(t||(t={}));var s,c,d,v=0;function f(){return++v}function p(e,t){var n=t.resolveItems();if(n.length<=0)return null;var o=t.resolveActiveIndex(),r=null!=o?o:-1,l=function(){switch(e.focus){case c.First:return n.findIndex((function(e){return!t.resolveDisabled(e)}));case c.Previous:var o=n.slice().reverse().findIndex((function(e,n,o){return!(-1!==r&&o.length-n-1>=r||t.resolveDisabled(e))}));return-1===o?o:n.length-1-o;case c.Next:return n.findIndex((function(e,n){return!(n<=r||t.resolveDisabled(e))}));case c.Last:var l=n.slice().reverse().findIndex((function(e){return!t.resolveDisabled(e)}));return-1===l?l:n.length-1-l;case c.Specific:return n.findIndex((function(n){return t.resolveId(n)===e.id}));case c.Nothing:return null;default:!function(e){throw new Error("Unexpected object: "+e)}(e)}}();return-1===l?o:l}function b(e,t){if(void 0!==e)return"function"==typeof e?e(t):e}!function(e){e.Space=" ",e.Enter="Enter",e.Escape="Escape",e.Backspace="Backspace",e.ArrowUp="ArrowUp",e.ArrowDown="ArrowDown",e.Home="Home",e.End="End",e.PageUp="PageUp",e.PageDown="PageDown",e.Tab="Tab"}(s||(s={})),function(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"}(c||(c={})),function(e){e[e.Open=0]="Open",e[e.Closed=1]="Closed"}(d||(d={}));var m=Symbol("MenuContext");function h(e){var t=n.inject(m,null);if(null===t){var o=new Error("<"+e+" /> is missing a parent <Menu /> component.");throw Error.captureStackTrace&&Error.captureStackTrace(o,h),o}return t}var x,y=n.defineComponent({props:{as:{type:[Object,String],default:"template"}},setup:function(e,t){var o=t.slots,r=t.attrs,l=n.ref(d.Closed),u=n.ref(null),i=n.ref(null),s=n.ref([]),v=n.ref(""),f=n.ref(null),b={menuState:l,buttonRef:u,itemsRef:i,items:s,searchQuery:v,activeItemIndex:f,closeMenu:function(){l.value=d.Closed,f.value=null},openMenu:function(){return l.value=d.Open},goToItem:function(e,t){var n=p(e===c.Specific?{focus:c.Specific,id:t}:{focus:e},{resolveItems:function(){return s.value},resolveActiveIndex:function(){return f.value},resolveId:function(e){return e.id},resolveDisabled:function(e){return e.dataRef.disabled}});""===v.value&&f.value===n||(v.value="",f.value=n)},search:function(e){v.value+=e;var t=s.value.findIndex((function(e){return e.dataRef.textValue.startsWith(v.value)&&!e.dataRef.disabled}));-1!==t&&t!==f.value&&(f.value=t)},clearSearch:function(){v.value=""},registerItem:function(e,t){s.value.push({id:e,dataRef:t})},unregisterItem:function(e){var t=s.value.slice(),n=null!==f.value?t[f.value]:null,o=t.findIndex((function(t){return t.id===e}));-1!==o&&t.splice(o,1),s.value=t,f.value=o===f.value||null===n?null:t.indexOf(n)}};return n.onMounted((function(){function e(e){var t,n,o,r=e.target,a=document.activeElement;l.value===d.Open&&((null==(t=u.value)?void 0:t.contains(r))||((null==(n=i.value)?void 0:n.contains(r))||b.closeMenu(),a!==document.body&&(null==a?void 0:a.contains(r))||e.defaultPrevented||null==(o=u.value)||o.focus({preventScroll:!0})))}window.addEventListener("mousedown",e),n.onUnmounted((function(){return window.removeEventListener("mousedown",e)}))})),n.provide(m,b),function(){return a({props:e,slot:{open:l.value===d.Open},slots:o,attrs:r})}}}),S=n.defineComponent({props:{disabled:{type:Boolean,default:!1},as:{type:[Object,String],default:"button"}},render:function(){var e,t=h("MenuButton"),n={open:t.menuState.value===d.Open},r={ref:"el",id:this.id,type:"button","aria-haspopup":!0,"aria-controls":null==(e=t.itemsRef.value)?void 0:e.id,"aria-expanded":t.menuState.value===d.Open||void 0,onKeyDown:this.handleKeyDown,onClick:this.handleClick};return a({props:o({},this.$props,r),slot:n,attrs:this.$attrs,slots:this.$slots})},setup:function(e){var t=h("MenuButton");return{id:"headlessui-menu-button-"+f(),el:t.buttonRef,handleKeyDown:function(e){switch(e.key){case s.Space:case s.Enter:case s.ArrowDown:e.preventDefault(),t.openMenu(),n.nextTick((function(){var e;null==(e=t.itemsRef.value)||e.focus({preventScroll:!0}),t.goToItem(c.First)}));break;case s.ArrowUp:e.preventDefault(),t.openMenu(),n.nextTick((function(){var e;null==(e=t.itemsRef.value)||e.focus({preventScroll:!0}),t.goToItem(c.Last)}))}},handleClick:function(o){var r;e.disabled||(t.menuState.value===d.Open?(t.closeMenu(),n.nextTick((function(){var e;return null==(e=t.buttonRef.value)?void 0:e.focus({preventScroll:!0})}))):(o.preventDefault(),t.openMenu(),r=function(){var e;return null==(e=t.itemsRef.value)?void 0:e.focus({preventScroll:!0})},requestAnimationFrame((function(){return requestAnimationFrame(r)}))))}}}}),g=n.defineComponent({props:{as:{type:[Object,String],default:"div"},static:{type:Boolean,default:!1},unmount:{type:Boolean,default:!0}},render:function(){var t,n,r=h("MenuItems"),l={open:r.menuState.value===d.Open},u={"aria-activedescendant":null===r.activeItemIndex.value||null==(t=r.items.value[r.activeItemIndex.value])?void 0:t.id,"aria-labelledby":null==(n=r.buttonRef.value)?void 0:n.id,id:this.id,onKeyDown:this.handleKeyDown,role:"menu",tabIndex:0,ref:"el"};return a({props:o({},this.$props,u),slot:l,attrs:this.$attrs,slots:this.$slots,features:e.RenderStrategy|e.Static,visible:l.open})},setup:function(){var e=h("MenuItems"),t="headlessui-menu-items-"+f(),o=n.ref(null);return n.watchEffect((function(){var t=e.itemsRef.value;if(t&&e.menuState.value===d.Open)for(var n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:function(e){return"menuitem"===e.getAttribute("role")?NodeFilter.FILTER_REJECT:e.hasAttribute("role")?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT}});n.nextNode();)n.currentNode.setAttribute("role","none")})),{id:t,el:e.itemsRef,handleKeyDown:function(t){switch(o.value&&clearTimeout(o.value),t.key){case s.Space:if(""!==e.searchQuery.value)return t.preventDefault(),e.search(t.key);case s.Enter:var r;t.preventDefault(),null!==e.activeItemIndex.value&&(null==(r=document.getElementById(e.items.value[e.activeItemIndex.value].id))||r.click()),e.closeMenu(),n.nextTick((function(){var t;return null==(t=e.buttonRef.value)?void 0:t.focus({preventScroll:!0})}));break;case s.ArrowDown:return t.preventDefault(),e.goToItem(c.Next);case s.ArrowUp:return t.preventDefault(),e.goToItem(c.Previous);case s.Home:case s.PageUp:return t.preventDefault(),e.goToItem(c.First);case s.End:case s.PageDown:return t.preventDefault(),e.goToItem(c.Last);case s.Escape:t.preventDefault(),e.closeMenu(),n.nextTick((function(){var t;return null==(t=e.buttonRef.value)?void 0:t.focus({preventScroll:!0})}));break;case s.Tab:return t.preventDefault();default:1===t.key.length&&(e.search(t.key),o.value=setTimeout((function(){return e.clearSearch()}),350))}}}}}),w=n.defineComponent({props:{as:{type:[Object,String],default:"template"},disabled:{type:Boolean,default:!1},class:{type:[String,Function],required:!1},className:{type:[String,Function],required:!1}},setup:function(e,t){var r=t.slots,l=t.attrs,u=h("MenuItem"),i="headlessui-menu-item-"+f(),s=e.disabled,v=e.className,p=void 0===v?e.class:v,m=n.computed((function(){return null!==u.activeItemIndex.value&&u.items.value[u.activeItemIndex.value].id===i})),x=n.ref({disabled:s,textValue:""});function y(e){if(s)return e.preventDefault();u.closeMenu(),n.nextTick((function(){var e;return null==(e=u.buttonRef.value)?void 0:e.focus({preventScroll:!0})}))}function S(){if(s)return u.goToItem(c.Nothing);u.goToItem(c.Specific,i)}function g(){s||m.value||u.goToItem(c.Specific,i)}function w(){s||m.value&&u.goToItem(c.Nothing)}return n.onMounted((function(){var e,t,n=null==(e=document.getElementById(i))||null==(t=e.textContent)?void 0:t.toLowerCase().trim();void 0!==n&&(x.value.textValue=n)})),n.onMounted((function(){return u.registerItem(i,x)})),n.onUnmounted((function(){return u.unregisterItem(i)})),n.watchEffect((function(){u.menuState.value===d.Open&&m.value&&n.nextTick((function(){var e;return null==(e=document.getElementById(i))||null==e.scrollIntoView?void 0:e.scrollIntoView({block:"nearest"})}))})),function(){var t={active:m.value,disabled:s},n={id:i,role:"menuitem",tabIndex:-1,class:b(p,t),"aria-disabled":!0===s||void 0,onClick:y,onFocus:S,onPointerMove:g,onMouseMove:g,onPointerLeave:w,onMouseLeave:w};return a({props:o({},e,n),slot:t,attrs:l,slots:r})}}});!function(e){e[e.Open=0]="Open",e[e.Closed=1]="Closed"}(x||(x={}));var O=Symbol("ListboxContext");function I(e){var t=n.inject(O,null);if(null===t){var o=new Error("<"+e+" /> is missing a parent <Listbox /> component.");throw Error.captureStackTrace&&Error.captureStackTrace(o,I),o}return t}var k=n.defineComponent({name:"Listbox",emits:["update:modelValue"],props:{as:{type:[Object,String],default:"template"},disabled:{type:[Boolean],default:!1},modelValue:{type:[Object,String,Number,Boolean],default:null}},setup:function(e,t){var o=t.slots,l=t.attrs,u=t.emit,i=e.disabled,s=r(e,["modelValue","disabled"]),d=n.ref(x.Closed),v=n.ref(null),f=n.ref(null),b=n.ref(null),m=n.ref([]),h=n.ref(""),y=n.ref(null),S=n.computed((function(){return e.modelValue})),g={listboxState:d,value:S,labelRef:v,buttonRef:f,optionsRef:b,disabled:i,options:m,searchQuery:h,activeOptionIndex:y,closeListbox:function(){i||d.value!==x.Closed&&(d.value=x.Closed,y.value=null)},openListbox:function(){i||d.value!==x.Open&&(d.value=x.Open)},goToOption:function(e,t){if(!i&&d.value!==x.Closed){var n=p(e===c.Specific?{focus:c.Specific,id:t}:{focus:e},{resolveItems:function(){return m.value},resolveActiveIndex:function(){return y.value},resolveId:function(e){return e.id},resolveDisabled:function(e){return e.dataRef.disabled}});""===h.value&&y.value===n||(h.value="",y.value=n)}},search:function(e){if(!i&&d.value!==x.Closed){h.value+=e;var t=m.value.findIndex((function(e){return!e.dataRef.disabled&&e.dataRef.textValue.startsWith(h.value)}));-1!==t&&t!==y.value&&(y.value=t)}},clearSearch:function(){i||d.value!==x.Closed&&""!==h.value&&(h.value="")},registerOption:function(e,t){m.value.push({id:e,dataRef:t})},unregisterOption:function(e){var t=m.value.slice(),n=null!==y.value?t[y.value]:null,o=t.findIndex((function(t){return t.id===e}));-1!==o&&t.splice(o,1),m.value=t,y.value=o===y.value||null===n?null:t.indexOf(n)},select:function(e){i||u("update:modelValue",e)}};return n.onMounted((function(){function e(e){var t,n,o,r=e.target,l=document.activeElement;d.value===x.Open&&((null==(t=f.value)?void 0:t.contains(r))||((null==(n=b.value)?void 0:n.contains(r))||g.closeListbox(),l!==document.body&&(null==l?void 0:l.contains(r))||e.defaultPrevented||null==(o=f.value)||o.focus({preventScroll:!0})))}window.addEventListener("mousedown",e),n.onUnmounted((function(){return window.removeEventListener("mousedown",e)}))})),n.provide(O,g),function(){return a({props:s,slot:{open:d.value===x.Open,disabled:i},slots:o,attrs:l})}}}),T=n.defineComponent({name:"ListboxLabel",props:{as:{type:[Object,String],default:"label"}},render:function(){var e=I("ListboxLabel"),t={open:e.listboxState.value===x.Open,disabled:e.disabled};return a({props:o({},this.$props,{id:this.id,ref:"el",onClick:this.handleClick}),slot:t,attrs:this.$attrs,slots:this.$slots})},setup:function(){var e=I("ListboxLabel");return{id:"headlessui-listbox-label-"+f(),el:e.labelRef,handleClick:function(){var t;null==(t=e.buttonRef.value)||t.focus({preventScroll:!0})}}}}),R=n.defineComponent({name:"ListboxButton",props:{as:{type:[Object,String],default:"button"}},render:function(){var e,t=I("ListboxButton"),n={open:t.listboxState.value===x.Open,disabled:t.disabled},r={ref:"el",id:this.id,type:"button","aria-haspopup":!0,"aria-controls":null==(e=t.optionsRef.value)?void 0:e.id,"aria-expanded":t.listboxState.value===x.Open||void 0,"aria-labelledby":t.labelRef.value?[t.labelRef.value.id,this.id].join(" "):void 0,disabled:t.disabled,onKeyDown:this.handleKeyDown,onClick:this.handleClick};return a({props:o({},this.$props,r),slot:n,attrs:this.$attrs,slots:this.$slots})},setup:function(){var e=I("ListboxButton");return{id:"headlessui-listbox-button-"+f(),el:e.buttonRef,handleKeyDown:function(t){switch(t.key){case s.Space:case s.Enter:case s.ArrowDown:t.preventDefault(),e.openListbox(),n.nextTick((function(){var t;null==(t=e.optionsRef.value)||t.focus({preventScroll:!0}),e.value.value||e.goToOption(c.First)}));break;case s.ArrowUp:t.preventDefault(),e.openListbox(),n.nextTick((function(){var t;null==(t=e.optionsRef.value)||t.focus({preventScroll:!0}),e.value.value||e.goToOption(c.Last)}))}},handleClick:function(t){var o;e.disabled||(e.listboxState.value===x.Open?(e.closeListbox(),n.nextTick((function(){var t;return null==(t=e.buttonRef.value)?void 0:t.focus({preventScroll:!0})}))):(t.preventDefault(),e.openListbox(),o=function(){var t;return null==(t=e.optionsRef.value)?void 0:t.focus({preventScroll:!0})},requestAnimationFrame((function(){return requestAnimationFrame(o)}))))}}}}),L=n.defineComponent({name:"ListboxOptions",props:{as:{type:[Object,String],default:"ul"},static:{type:Boolean,default:!1},unmount:{type:Boolean,default:!0}},render:function(){var t,n,r,l,u=I("ListboxOptions"),i={open:u.listboxState.value===x.Open},s={"aria-activedescendant":null===u.activeOptionIndex.value||null==(t=u.options.value[u.activeOptionIndex.value])?void 0:t.id,"aria-labelledby":null!=(n=null==(r=u.labelRef.value)?void 0:r.id)?n:null==(l=u.buttonRef.value)?void 0:l.id,id:this.id,onKeyDown:this.handleKeyDown,role:"listbox",tabIndex:0,ref:"el"};return a({props:o({},this.$props,s),slot:i,attrs:this.$attrs,slots:this.$slots,features:e.RenderStrategy|e.Static,visible:i.open})},setup:function(){var e=I("ListboxOptions"),t="headlessui-listbox-options-"+f(),o=n.ref(null);return{id:t,el:e.optionsRef,handleKeyDown:function(t){switch(o.value&&clearTimeout(o.value),t.key){case s.Space:if(""!==e.searchQuery.value)return t.preventDefault(),e.search(t.key);case s.Enter:t.preventDefault(),null!==e.activeOptionIndex.value&&e.select(e.options.value[e.activeOptionIndex.value].dataRef.value),e.closeListbox(),n.nextTick((function(){var t;return null==(t=e.buttonRef.value)?void 0:t.focus({preventScroll:!0})}));break;case s.ArrowDown:return t.preventDefault(),e.goToOption(c.Next);case s.ArrowUp:return t.preventDefault(),e.goToOption(c.Previous);case s.Home:case s.PageUp:return t.preventDefault(),e.goToOption(c.First);case s.End:case s.PageDown:return t.preventDefault(),e.goToOption(c.Last);case s.Escape:t.preventDefault(),e.closeListbox(),n.nextTick((function(){var t;return null==(t=e.buttonRef.value)?void 0:t.focus({preventScroll:!0})}));break;case s.Tab:return t.preventDefault();default:1===t.key.length&&(e.search(t.key),o.value=setTimeout((function(){return e.clearSearch()}),350))}}}}}),D=n.defineComponent({name:"ListboxOption",props:{as:{type:[Object,String],default:"li"},value:{type:[Object,String],default:null},disabled:{type:Boolean,default:!1},class:{type:[String,Function],required:!1},className:{type:[String,Function],required:!1}},setup:function(e,t){var r=t.slots,l=t.attrs,u=I("ListboxOption"),i="headlessui-listbox-option-"+f(),s=e.disabled,d=e.className,v=void 0===d?e.class:d,p=e.value,m=n.computed((function(){return null!==u.activeOptionIndex.value&&u.options.value[u.activeOptionIndex.value].id===i})),h=n.computed((function(){return n.toRaw(u.value.value)===n.toRaw(p)})),y=n.ref({disabled:s,value:p,textValue:""});function S(e){if(s)return e.preventDefault();u.select(p),u.closeListbox(),n.nextTick((function(){var e;return null==(e=u.buttonRef.value)?void 0:e.focus({preventScroll:!0})}))}function g(){if(s)return u.goToOption(c.Nothing);u.goToOption(c.Specific,i)}function w(){s||m.value||u.goToOption(c.Specific,i)}function O(){s||m.value&&u.goToOption(c.Nothing)}return n.onMounted((function(){var e,t,n=null==(e=document.getElementById(i))||null==(t=e.textContent)?void 0:t.toLowerCase().trim();void 0!==n&&(y.value.textValue=n)})),n.onMounted((function(){return u.registerOption(i,y)})),n.onUnmounted((function(){return u.unregisterOption(i)})),n.onMounted((function(){n.watch([u.listboxState,h],(function(){var e;u.listboxState.value===x.Open&&h.value&&(u.goToOption(c.Specific,i),null==(e=document.getElementById(i))||null==e.focus||e.focus())}),{immediate:!0})})),n.watchEffect((function(){u.listboxState.value===x.Open&&m.value&&n.nextTick((function(){var e;return null==(e=document.getElementById(i))||null==e.scrollIntoView?void 0:e.scrollIntoView({block:"nearest"})}))})),function(){var t={active:m.value,selected:h.value,disabled:s},n={id:i,role:"option",tabIndex:-1,class:b(v,t),"aria-disabled":!0===s||void 0,"aria-selected":!0===h.value?h.value:void 0,onClick:S,onFocus:g,onPointerMove:w,onMouseMove:w,onPointerLeave:O,onMouseLeave:O};return a({props:o({},e,n),slot:t,attrs:l,slots:r})}}}),E=Symbol("GroupContext");function C(e){var t=n.inject(E,null);if(null===t){var o=new Error("<"+e+" /> is missing a parent <SwitchGroup /> component.");throw Error.captureStackTrace&&Error.captureStackTrace(o,C),o}return t}var M=n.defineComponent({name:"SwitchGroup",props:{as:{type:[Object,String],default:"template"}},setup:function(e,t){var o=t.slots,r=t.attrs,l=n.ref(null),u=n.ref(null);return n.provide(E,{switchRef:l,labelRef:u}),function(){return a({props:e,slot:{},slots:o,attrs:r})}}}),j=n.defineComponent({name:"Switch",emits:["update:modelValue"],props:{as:{type:[Object,String],default:"button"},modelValue:{type:[Object,Boolean],default:null},class:{type:[String,Function],required:!1},className:{type:[String,Function],required:!1}},render:function(){var e=n.inject(E,null),t=this.$props,r=t.className,l=void 0===r?t.class:r,u=n.computed((function(){var t;return null==e||null==(t=e.labelRef.value)?void 0:t.id})),i={checked:this.$props.modelValue},s={id:this.id,ref:null===e?void 0:e.switchRef,role:"switch",tabIndex:0,class:b(l,i),"aria-checked":this.$props.modelValue,"aria-labelledby":u.value,onClick:this.handleClick,onKeyUp:this.handleKeyUp,onKeyPress:this.handleKeyPress};return"button"===this.$props.as&&Object.assign(s,{type:"button"}),a({props:o({},this.$props,s),slot:i,attrs:this.$attrs,slots:this.$slots})},setup:function(e,t){var o=t.emit,r=n.inject(E,null);function l(){o("update:modelValue",!e.modelValue)}return{id:"headlessui-switch-"+f(),el:null==r?void 0:r.switchRef,handleClick:function(e){e.preventDefault(),l()},handleKeyUp:function(e){e.key!==s.Tab&&e.preventDefault(),e.key===s.Space&&l()},handleKeyPress:function(e){e.preventDefault()}}}}),N=n.defineComponent({name:"SwitchLabel",props:{as:{type:[Object,String],default:"label"}},render:function(){return a({props:o({},this.$props,{id:this.id,ref:"el",onClick:this.handleClick}),slot:{},attrs:this.$attrs,slots:this.$slots})},setup:function(){var e=C("SwitchLabel");return{id:"headlessui-switch-label-"+f(),el:e.labelRef,handleClick:function(){var t,n;null==(t=e.switchRef.value)||t.click(),null==(n=e.switchRef.value)||n.focus({preventScroll:!0})}}}});exports.Listbox=k,exports.ListboxButton=R,exports.ListboxLabel=T,exports.ListboxOption=D,exports.ListboxOptions=L,exports.Menu=y,exports.MenuButton=S,exports.MenuItem=w,exports.MenuItems=g,exports.Switch=j,exports.SwitchGroup=M,exports.SwitchLabel=N; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t,n=require("vue");function o(){return(o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e}).apply(this,arguments)}function r(e,t){if(null==e)return{};var n,o,r={},l=Object.keys(e);for(o=0;o<l.length;o++)t.indexOf(n=l[o])>=0||(r[n]=e[n]);return r}function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}function u(e,t){if(e in t){for(var n=t[e],o=arguments.length,r=new Array(o>2?o-2:0),l=2;l<o;l++)r[l-2]=arguments[l];return"function"==typeof n?n.apply(void 0,r):n}var a=new Error('Tried to handle "'+e+'" but there is no handler defined. Only defined handlers are: '+Object.keys(t).map((function(e){return'"'+e+'"'})).join(", ")+".");throw Error.captureStackTrace&&Error.captureStackTrace(a,u),a}function a(n){var l,a,s=n.visible,c=void 0===s||s,d=n.features,v=void 0===d?e.None:d,f=r(n,["visible","features"]);return c||v&e.Static&&f.props.static?i(f):v&e.RenderStrategy?u(null==(l=f.props.unmount)||l?t.Unmount:t.Hidden,((a={})[t.Unmount]=function(){return null},a[t.Hidden]=function(){return i(o({},f,{props:o({},f.props,{hidden:!0,style:{display:"none"}})}))},a)):i(f)}function i(e){var t=e.attrs,o=e.slots,u=e.slot,a=function(e,t){void 0===t&&(t=[]);for(var n,o=Object.assign({},e),r=function(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return l(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?l(e,void 0):void 0}}(e))){n&&(e=n);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}(t);!(n=r()).done;){var u=n.value;u in o&&delete o[u]}return o}(e.props,["unmount","static"]),i=a.as,s=r(a,["as"]),c=null==o.default?void 0:o.default(u);if("template"===i){if(Object.keys(s).length>0||"class"in t){var d=null!=c?c:[],v=d[0];if(d.slice(1).length>0)throw new Error('You should only render 1 child or use the `as="..."` prop');return n.cloneVNode(v,s)}return c}return n.h(i,s,c)}!function(e){e[e.None=0]="None",e[e.RenderStrategy=1]="RenderStrategy",e[e.Static=2]="Static"}(e||(e={})),function(e){e[e.Unmount=0]="Unmount",e[e.Hidden=1]="Hidden"}(t||(t={}));var s,c,d,v=0;function f(){return++v}function p(e,t){var n=t.resolveItems();if(n.length<=0)return null;var o=t.resolveActiveIndex(),r=null!=o?o:-1,l=function(){switch(e.focus){case c.First:return n.findIndex((function(e){return!t.resolveDisabled(e)}));case c.Previous:var o=n.slice().reverse().findIndex((function(e,n,o){return!(-1!==r&&o.length-n-1>=r||t.resolveDisabled(e))}));return-1===o?o:n.length-1-o;case c.Next:return n.findIndex((function(e,n){return!(n<=r||t.resolveDisabled(e))}));case c.Last:var l=n.slice().reverse().findIndex((function(e){return!t.resolveDisabled(e)}));return-1===l?l:n.length-1-l;case c.Specific:return n.findIndex((function(n){return t.resolveId(n)===e.id}));case c.Nothing:return null;default:!function(e){throw new Error("Unexpected object: "+e)}(e)}}();return-1===l?o:l}function b(e,t){if(void 0!==e)return"function"==typeof e?e(t):e}!function(e){e.Space=" ",e.Enter="Enter",e.Escape="Escape",e.Backspace="Backspace",e.ArrowUp="ArrowUp",e.ArrowDown="ArrowDown",e.Home="Home",e.End="End",e.PageUp="PageUp",e.PageDown="PageDown",e.Tab="Tab"}(s||(s={})),function(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"}(c||(c={})),function(e){e[e.Open=0]="Open",e[e.Closed=1]="Closed"}(d||(d={}));var m=Symbol("MenuContext");function h(e){var t=n.inject(m,null);if(null===t){var o=new Error("<"+e+" /> is missing a parent <Menu /> component.");throw Error.captureStackTrace&&Error.captureStackTrace(o,h),o}return t}var x,y=n.defineComponent({props:{as:{type:[Object,String],default:"template"}},setup:function(e,t){var o=t.slots,r=t.attrs,l=n.ref(d.Closed),u=n.ref(null),i=n.ref(null),s=n.ref([]),v=n.ref(""),f=n.ref(null),b={menuState:l,buttonRef:u,itemsRef:i,items:s,searchQuery:v,activeItemIndex:f,closeMenu:function(){l.value=d.Closed,f.value=null},openMenu:function(){return l.value=d.Open},goToItem:function(e,t){var n=p(e===c.Specific?{focus:c.Specific,id:t}:{focus:e},{resolveItems:function(){return s.value},resolveActiveIndex:function(){return f.value},resolveId:function(e){return e.id},resolveDisabled:function(e){return e.dataRef.disabled}});""===v.value&&f.value===n||(v.value="",f.value=n)},search:function(e){v.value+=e;var t=s.value.findIndex((function(e){return e.dataRef.textValue.startsWith(v.value)&&!e.dataRef.disabled}));-1!==t&&t!==f.value&&(f.value=t)},clearSearch:function(){v.value=""},registerItem:function(e,t){s.value.push({id:e,dataRef:t})},unregisterItem:function(e){var t=s.value.slice(),n=null!==f.value?t[f.value]:null,o=t.findIndex((function(t){return t.id===e}));-1!==o&&t.splice(o,1),s.value=t,f.value=o===f.value||null===n?null:t.indexOf(n)}};return n.onMounted((function(){function e(e){var t,n,o,r=e.target,a=document.activeElement;l.value===d.Open&&((null==(t=u.value)?void 0:t.contains(r))||((null==(n=i.value)?void 0:n.contains(r))||b.closeMenu(),a!==document.body&&(null==a?void 0:a.contains(r))||e.defaultPrevented||null==(o=u.value)||o.focus({preventScroll:!0})))}window.addEventListener("mousedown",e),n.onUnmounted((function(){return window.removeEventListener("mousedown",e)}))})),n.provide(m,b),function(){return a({props:e,slot:{open:l.value===d.Open},slots:o,attrs:r})}}}),S=n.defineComponent({props:{disabled:{type:Boolean,default:!1},as:{type:[Object,String],default:"button"}},render:function(){var e,t=h("MenuButton"),n={open:t.menuState.value===d.Open},r={ref:"el",id:this.id,type:"button","aria-haspopup":!0,"aria-controls":null==(e=t.itemsRef.value)?void 0:e.id,"aria-expanded":t.menuState.value===d.Open||void 0,onKeydown:this.handleKeyDown,onClick:this.handleClick};return a({props:o({},this.$props,r),slot:n,attrs:this.$attrs,slots:this.$slots})},setup:function(e){var t=h("MenuButton");return{id:"headlessui-menu-button-"+f(),el:t.buttonRef,handleKeyDown:function(e){switch(e.key){case s.Space:case s.Enter:case s.ArrowDown:e.preventDefault(),t.openMenu(),n.nextTick((function(){var e;null==(e=t.itemsRef.value)||e.focus({preventScroll:!0}),t.goToItem(c.First)}));break;case s.ArrowUp:e.preventDefault(),t.openMenu(),n.nextTick((function(){var e;null==(e=t.itemsRef.value)||e.focus({preventScroll:!0}),t.goToItem(c.Last)}))}},handleClick:function(o){var r;e.disabled||(t.menuState.value===d.Open?(t.closeMenu(),n.nextTick((function(){var e;return null==(e=t.buttonRef.value)?void 0:e.focus({preventScroll:!0})}))):(o.preventDefault(),t.openMenu(),r=function(){var e;return null==(e=t.itemsRef.value)?void 0:e.focus({preventScroll:!0})},requestAnimationFrame((function(){return requestAnimationFrame(r)}))))}}}}),g=n.defineComponent({props:{as:{type:[Object,String],default:"div"},static:{type:Boolean,default:!1},unmount:{type:Boolean,default:!0}},render:function(){var t,n,r=h("MenuItems"),l={open:r.menuState.value===d.Open},u={"aria-activedescendant":null===r.activeItemIndex.value||null==(t=r.items.value[r.activeItemIndex.value])?void 0:t.id,"aria-labelledby":null==(n=r.buttonRef.value)?void 0:n.id,id:this.id,onKeydown:this.handleKeyDown,role:"menu",tabIndex:0,ref:"el"};return a({props:o({},this.$props,u),slot:l,attrs:this.$attrs,slots:this.$slots,features:e.RenderStrategy|e.Static,visible:l.open})},setup:function(){var e=h("MenuItems"),t="headlessui-menu-items-"+f(),o=n.ref(null);return n.watchEffect((function(){var t=e.itemsRef.value;if(t&&e.menuState.value===d.Open)for(var n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:function(e){return"menuitem"===e.getAttribute("role")?NodeFilter.FILTER_REJECT:e.hasAttribute("role")?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT}});n.nextNode();)n.currentNode.setAttribute("role","none")})),{id:t,el:e.itemsRef,handleKeyDown:function(t){switch(o.value&&clearTimeout(o.value),t.key){case s.Space:if(""!==e.searchQuery.value)return t.preventDefault(),e.search(t.key);case s.Enter:var r;t.preventDefault(),null!==e.activeItemIndex.value&&(null==(r=document.getElementById(e.items.value[e.activeItemIndex.value].id))||r.click()),e.closeMenu(),n.nextTick((function(){var t;return null==(t=e.buttonRef.value)?void 0:t.focus({preventScroll:!0})}));break;case s.ArrowDown:return t.preventDefault(),e.goToItem(c.Next);case s.ArrowUp:return t.preventDefault(),e.goToItem(c.Previous);case s.Home:case s.PageUp:return t.preventDefault(),e.goToItem(c.First);case s.End:case s.PageDown:return t.preventDefault(),e.goToItem(c.Last);case s.Escape:t.preventDefault(),e.closeMenu(),n.nextTick((function(){var t;return null==(t=e.buttonRef.value)?void 0:t.focus({preventScroll:!0})}));break;case s.Tab:return t.preventDefault();default:1===t.key.length&&(e.search(t.key),o.value=setTimeout((function(){return e.clearSearch()}),350))}}}}}),w=n.defineComponent({props:{as:{type:[Object,String],default:"template"},disabled:{type:Boolean,default:!1},class:{type:[String,Function],required:!1},className:{type:[String,Function],required:!1}},setup:function(e,t){var r=t.slots,l=t.attrs,u=h("MenuItem"),i="headlessui-menu-item-"+f(),s=e.disabled,v=e.className,p=void 0===v?e.class:v,m=n.computed((function(){return null!==u.activeItemIndex.value&&u.items.value[u.activeItemIndex.value].id===i})),x=n.ref({disabled:s,textValue:""});function y(e){if(s)return e.preventDefault();u.closeMenu(),n.nextTick((function(){var e;return null==(e=u.buttonRef.value)?void 0:e.focus({preventScroll:!0})}))}function S(){if(s)return u.goToItem(c.Nothing);u.goToItem(c.Specific,i)}function g(){s||m.value||u.goToItem(c.Specific,i)}function w(){s||m.value&&u.goToItem(c.Nothing)}return n.onMounted((function(){var e,t,n=null==(e=document.getElementById(i))||null==(t=e.textContent)?void 0:t.toLowerCase().trim();void 0!==n&&(x.value.textValue=n)})),n.onMounted((function(){return u.registerItem(i,x)})),n.onUnmounted((function(){return u.unregisterItem(i)})),n.watchEffect((function(){u.menuState.value===d.Open&&m.value&&n.nextTick((function(){var e;return null==(e=document.getElementById(i))||null==e.scrollIntoView?void 0:e.scrollIntoView({block:"nearest"})}))})),function(){var t={active:m.value,disabled:s},n={id:i,role:"menuitem",tabIndex:-1,class:b(p,t),"aria-disabled":!0===s||void 0,onClick:y,onFocus:S,onPointermove:g,onMousemove:g,onPointerleave:w,onMouseleave:w};return a({props:o({},e,n),slot:t,attrs:l,slots:r})}}});!function(e){e[e.Open=0]="Open",e[e.Closed=1]="Closed"}(x||(x={}));var O=Symbol("ListboxContext");function I(e){var t=n.inject(O,null);if(null===t){var o=new Error("<"+e+" /> is missing a parent <Listbox /> component.");throw Error.captureStackTrace&&Error.captureStackTrace(o,I),o}return t}var k=n.defineComponent({name:"Listbox",emits:["update:modelValue"],props:{as:{type:[Object,String],default:"template"},disabled:{type:[Boolean],default:!1},modelValue:{type:[Object,String,Number,Boolean],default:null}},setup:function(e,t){var o=t.slots,l=t.attrs,u=t.emit,i=e.disabled,s=r(e,["modelValue","disabled"]),d=n.ref(x.Closed),v=n.ref(null),f=n.ref(null),b=n.ref(null),m=n.ref([]),h=n.ref(""),y=n.ref(null),S=n.computed((function(){return e.modelValue})),g={listboxState:d,value:S,labelRef:v,buttonRef:f,optionsRef:b,disabled:i,options:m,searchQuery:h,activeOptionIndex:y,closeListbox:function(){i||d.value!==x.Closed&&(d.value=x.Closed,y.value=null)},openListbox:function(){i||d.value!==x.Open&&(d.value=x.Open)},goToOption:function(e,t){if(!i&&d.value!==x.Closed){var n=p(e===c.Specific?{focus:c.Specific,id:t}:{focus:e},{resolveItems:function(){return m.value},resolveActiveIndex:function(){return y.value},resolveId:function(e){return e.id},resolveDisabled:function(e){return e.dataRef.disabled}});""===h.value&&y.value===n||(h.value="",y.value=n)}},search:function(e){if(!i&&d.value!==x.Closed){h.value+=e;var t=m.value.findIndex((function(e){return!e.dataRef.disabled&&e.dataRef.textValue.startsWith(h.value)}));-1!==t&&t!==y.value&&(y.value=t)}},clearSearch:function(){i||d.value!==x.Closed&&""!==h.value&&(h.value="")},registerOption:function(e,t){m.value.push({id:e,dataRef:t})},unregisterOption:function(e){var t=m.value.slice(),n=null!==y.value?t[y.value]:null,o=t.findIndex((function(t){return t.id===e}));-1!==o&&t.splice(o,1),m.value=t,y.value=o===y.value||null===n?null:t.indexOf(n)},select:function(e){i||u("update:modelValue",e)}};return n.onMounted((function(){function e(e){var t,n,o,r=e.target,l=document.activeElement;d.value===x.Open&&((null==(t=f.value)?void 0:t.contains(r))||((null==(n=b.value)?void 0:n.contains(r))||g.closeListbox(),l!==document.body&&(null==l?void 0:l.contains(r))||e.defaultPrevented||null==(o=f.value)||o.focus({preventScroll:!0})))}window.addEventListener("mousedown",e),n.onUnmounted((function(){return window.removeEventListener("mousedown",e)}))})),n.provide(O,g),function(){return a({props:s,slot:{open:d.value===x.Open,disabled:i},slots:o,attrs:l})}}}),T=n.defineComponent({name:"ListboxLabel",props:{as:{type:[Object,String],default:"label"}},render:function(){var e=I("ListboxLabel"),t={open:e.listboxState.value===x.Open,disabled:e.disabled};return a({props:o({},this.$props,{id:this.id,ref:"el",onClick:this.handleClick}),slot:t,attrs:this.$attrs,slots:this.$slots})},setup:function(){var e=I("ListboxLabel");return{id:"headlessui-listbox-label-"+f(),el:e.labelRef,handleClick:function(){var t;null==(t=e.buttonRef.value)||t.focus({preventScroll:!0})}}}}),R=n.defineComponent({name:"ListboxButton",props:{as:{type:[Object,String],default:"button"}},render:function(){var e,t=I("ListboxButton"),n={open:t.listboxState.value===x.Open,disabled:t.disabled},r={ref:"el",id:this.id,type:"button","aria-haspopup":!0,"aria-controls":null==(e=t.optionsRef.value)?void 0:e.id,"aria-expanded":t.listboxState.value===x.Open||void 0,"aria-labelledby":t.labelRef.value?[t.labelRef.value.id,this.id].join(" "):void 0,disabled:t.disabled,onKeydown:this.handleKeyDown,onClick:this.handleClick};return a({props:o({},this.$props,r),slot:n,attrs:this.$attrs,slots:this.$slots})},setup:function(){var e=I("ListboxButton");return{id:"headlessui-listbox-button-"+f(),el:e.buttonRef,handleKeyDown:function(t){switch(t.key){case s.Space:case s.Enter:case s.ArrowDown:t.preventDefault(),e.openListbox(),n.nextTick((function(){var t;null==(t=e.optionsRef.value)||t.focus({preventScroll:!0}),e.value.value||e.goToOption(c.First)}));break;case s.ArrowUp:t.preventDefault(),e.openListbox(),n.nextTick((function(){var t;null==(t=e.optionsRef.value)||t.focus({preventScroll:!0}),e.value.value||e.goToOption(c.Last)}))}},handleClick:function(t){var o;e.disabled||(e.listboxState.value===x.Open?(e.closeListbox(),n.nextTick((function(){var t;return null==(t=e.buttonRef.value)?void 0:t.focus({preventScroll:!0})}))):(t.preventDefault(),e.openListbox(),o=function(){var t;return null==(t=e.optionsRef.value)?void 0:t.focus({preventScroll:!0})},requestAnimationFrame((function(){return requestAnimationFrame(o)}))))}}}}),E=n.defineComponent({name:"ListboxOptions",props:{as:{type:[Object,String],default:"ul"},static:{type:Boolean,default:!1},unmount:{type:Boolean,default:!0}},render:function(){var t,n,r,l,u=I("ListboxOptions"),i={open:u.listboxState.value===x.Open},s={"aria-activedescendant":null===u.activeOptionIndex.value||null==(t=u.options.value[u.activeOptionIndex.value])?void 0:t.id,"aria-labelledby":null!=(n=null==(r=u.labelRef.value)?void 0:r.id)?n:null==(l=u.buttonRef.value)?void 0:l.id,id:this.id,onKeydown:this.handleKeyDown,role:"listbox",tabIndex:0,ref:"el"};return a({props:o({},this.$props,s),slot:i,attrs:this.$attrs,slots:this.$slots,features:e.RenderStrategy|e.Static,visible:i.open})},setup:function(){var e=I("ListboxOptions"),t="headlessui-listbox-options-"+f(),o=n.ref(null);return{id:t,el:e.optionsRef,handleKeyDown:function(t){switch(o.value&&clearTimeout(o.value),t.key){case s.Space:if(""!==e.searchQuery.value)return t.preventDefault(),e.search(t.key);case s.Enter:t.preventDefault(),null!==e.activeOptionIndex.value&&e.select(e.options.value[e.activeOptionIndex.value].dataRef.value),e.closeListbox(),n.nextTick((function(){var t;return null==(t=e.buttonRef.value)?void 0:t.focus({preventScroll:!0})}));break;case s.ArrowDown:return t.preventDefault(),e.goToOption(c.Next);case s.ArrowUp:return t.preventDefault(),e.goToOption(c.Previous);case s.Home:case s.PageUp:return t.preventDefault(),e.goToOption(c.First);case s.End:case s.PageDown:return t.preventDefault(),e.goToOption(c.Last);case s.Escape:t.preventDefault(),e.closeListbox(),n.nextTick((function(){var t;return null==(t=e.buttonRef.value)?void 0:t.focus({preventScroll:!0})}));break;case s.Tab:return t.preventDefault();default:1===t.key.length&&(e.search(t.key),o.value=setTimeout((function(){return e.clearSearch()}),350))}}}}}),L=n.defineComponent({name:"ListboxOption",props:{as:{type:[Object,String],default:"li"},value:{type:[Object,String],default:null},disabled:{type:Boolean,default:!1},class:{type:[String,Function],required:!1},className:{type:[String,Function],required:!1}},setup:function(e,t){var r=t.slots,l=t.attrs,u=I("ListboxOption"),i="headlessui-listbox-option-"+f(),s=e.disabled,d=e.className,v=void 0===d?e.class:d,p=e.value,m=n.computed((function(){return null!==u.activeOptionIndex.value&&u.options.value[u.activeOptionIndex.value].id===i})),h=n.computed((function(){return n.toRaw(u.value.value)===n.toRaw(p)})),y=n.ref({disabled:s,value:p,textValue:""});function S(e){if(s)return e.preventDefault();u.select(p),u.closeListbox(),n.nextTick((function(){var e;return null==(e=u.buttonRef.value)?void 0:e.focus({preventScroll:!0})}))}function g(){if(s)return u.goToOption(c.Nothing);u.goToOption(c.Specific,i)}function w(){s||m.value||u.goToOption(c.Specific,i)}function O(){s||m.value&&u.goToOption(c.Nothing)}return n.onMounted((function(){var e,t,n=null==(e=document.getElementById(i))||null==(t=e.textContent)?void 0:t.toLowerCase().trim();void 0!==n&&(y.value.textValue=n)})),n.onMounted((function(){return u.registerOption(i,y)})),n.onUnmounted((function(){return u.unregisterOption(i)})),n.onMounted((function(){n.watch([u.listboxState,h],(function(){var e;u.listboxState.value===x.Open&&h.value&&(u.goToOption(c.Specific,i),null==(e=document.getElementById(i))||null==e.focus||e.focus())}),{immediate:!0})})),n.watchEffect((function(){u.listboxState.value===x.Open&&m.value&&n.nextTick((function(){var e;return null==(e=document.getElementById(i))||null==e.scrollIntoView?void 0:e.scrollIntoView({block:"nearest"})}))})),function(){var t={active:m.value,selected:h.value,disabled:s},n={id:i,role:"option",tabIndex:-1,class:b(v,t),"aria-disabled":!0===s||void 0,"aria-selected":!0===h.value?h.value:void 0,onClick:S,onFocus:g,onPointermove:w,onMousemove:w,onPointerleave:O,onMouseleave:O};return a({props:o({},e,n),slot:t,attrs:l,slots:r})}}}),C=Symbol("GroupContext");function D(e){var t=n.inject(C,null);if(null===t){var o=new Error("<"+e+" /> is missing a parent <SwitchGroup /> component.");throw Error.captureStackTrace&&Error.captureStackTrace(o,D),o}return t}var M=n.defineComponent({name:"SwitchGroup",props:{as:{type:[Object,String],default:"template"}},setup:function(e,t){var o=t.slots,r=t.attrs,l=n.ref(null),u=n.ref(null);return n.provide(C,{switchRef:l,labelRef:u}),function(){return a({props:e,slot:{},slots:o,attrs:r})}}}),j=n.defineComponent({name:"Switch",emits:["update:modelValue"],props:{as:{type:[Object,String],default:"button"},modelValue:{type:[Object,Boolean],default:null},class:{type:[String,Function],required:!1},className:{type:[String,Function],required:!1}},render:function(){var e=n.inject(C,null),t=this.$props,r=t.className,l=void 0===r?t.class:r,u=n.computed((function(){var t;return null==e||null==(t=e.labelRef.value)?void 0:t.id})),i={checked:this.$props.modelValue},s={id:this.id,ref:null===e?void 0:e.switchRef,role:"switch",tabIndex:0,class:b(l,i),"aria-checked":this.$props.modelValue,"aria-labelledby":u.value,onClick:this.handleClick,onKeyup:this.handleKeyUp,onKeypress:this.handleKeyPress};return"button"===this.$props.as&&Object.assign(s,{type:"button"}),a({props:o({},this.$props,s),slot:i,attrs:this.$attrs,slots:this.$slots})},setup:function(e,t){var o=t.emit,r=n.inject(C,null);function l(){o("update:modelValue",!e.modelValue)}return{id:"headlessui-switch-"+f(),el:null==r?void 0:r.switchRef,handleClick:function(e){e.preventDefault(),l()},handleKeyUp:function(e){e.key!==s.Tab&&e.preventDefault(),e.key===s.Space&&l()},handleKeyPress:function(e){e.preventDefault()}}}}),N=n.defineComponent({name:"SwitchLabel",props:{as:{type:[Object,String],default:"label"}},render:function(){return a({props:o({},this.$props,{id:this.id,ref:"el",onClick:this.handleClick}),slot:{},attrs:this.$attrs,slots:this.$slots})},setup:function(){var e=D("SwitchLabel");return{id:"headlessui-switch-label-"+f(),el:e.labelRef,handleClick:function(){var t,n;null==(t=e.switchRef.value)||t.click(),null==(n=e.switchRef.value)||n.focus({preventScroll:!0})}}}});exports.Listbox=k,exports.ListboxButton=R,exports.ListboxLabel=T,exports.ListboxOption=L,exports.ListboxOptions=E,exports.Menu=y,exports.MenuButton=S,exports.MenuItem=w,exports.MenuItems=g,exports.Switch=j,exports.SwitchGroup=M,exports.SwitchLabel=N; | ||
//# sourceMappingURL=headlessui.cjs.production.min.js.map |
@@ -498,3 +498,3 @@ import { cloneVNode, h, defineComponent, ref, onMounted, onUnmounted, provide, watchEffect, computed, nextTick, inject, toRaw, watch } from 'vue'; | ||
'aria-expanded': api.menuState.value === MenuStates.Open ? true : undefined, | ||
onKeyDown: this.handleKeyDown, | ||
onKeydown: this.handleKeyDown, | ||
onClick: this.handleClick | ||
@@ -605,3 +605,3 @@ }; | ||
id: this.id, | ||
onKeyDown: this.handleKeyDown, | ||
onKeydown: this.handleKeyDown, | ||
role: 'menu', | ||
@@ -829,6 +829,6 @@ tabIndex: 0, | ||
onFocus: handleFocus, | ||
onPointerMove: handleMove, | ||
onMouseMove: handleMove, | ||
onPointerLeave: handleLeave, | ||
onMouseLeave: handleLeave | ||
onPointermove: handleMove, | ||
onMousemove: handleMove, | ||
onPointerleave: handleLeave, | ||
onMouseleave: handleLeave | ||
}; | ||
@@ -1106,3 +1106,3 @@ return render({ | ||
disabled: api.disabled, | ||
onKeyDown: this.handleKeyDown, | ||
onKeydown: this.handleKeyDown, | ||
onClick: this.handleClick | ||
@@ -1215,3 +1215,3 @@ }; | ||
id: this.id, | ||
onKeyDown: this.handleKeyDown, | ||
onKeydown: this.handleKeyDown, | ||
role: 'listbox', | ||
@@ -1446,6 +1446,6 @@ tabIndex: 0, | ||
onFocus: handleFocus, | ||
onPointerMove: handleMove, | ||
onMouseMove: handleMove, | ||
onPointerLeave: handleLeave, | ||
onMouseLeave: handleLeave | ||
onPointermove: handleMove, | ||
onMousemove: handleMove, | ||
onPointerleave: handleLeave, | ||
onMouseleave: handleLeave | ||
}; | ||
@@ -1550,4 +1550,4 @@ return render({ | ||
onClick: this.handleClick, | ||
onKeyUp: this.handleKeyUp, | ||
onKeyPress: this.handleKeyPress | ||
onKeyup: this.handleKeyUp, | ||
onKeypress: this.handleKeyPress | ||
}; | ||
@@ -1554,0 +1554,0 @@ |
@@ -502,3 +502,3 @@ (function (global, factory) { | ||
'aria-expanded': api.menuState.value === MenuStates.Open ? true : undefined, | ||
onKeyDown: this.handleKeyDown, | ||
onKeydown: this.handleKeyDown, | ||
onClick: this.handleClick | ||
@@ -609,3 +609,3 @@ }; | ||
id: this.id, | ||
onKeyDown: this.handleKeyDown, | ||
onKeydown: this.handleKeyDown, | ||
role: 'menu', | ||
@@ -833,6 +833,6 @@ tabIndex: 0, | ||
onFocus: handleFocus, | ||
onPointerMove: handleMove, | ||
onMouseMove: handleMove, | ||
onPointerLeave: handleLeave, | ||
onMouseLeave: handleLeave | ||
onPointermove: handleMove, | ||
onMousemove: handleMove, | ||
onPointerleave: handleLeave, | ||
onMouseleave: handleLeave | ||
}; | ||
@@ -1110,3 +1110,3 @@ return render({ | ||
disabled: api.disabled, | ||
onKeyDown: this.handleKeyDown, | ||
onKeydown: this.handleKeyDown, | ||
onClick: this.handleClick | ||
@@ -1219,3 +1219,3 @@ }; | ||
id: this.id, | ||
onKeyDown: this.handleKeyDown, | ||
onKeydown: this.handleKeyDown, | ||
role: 'listbox', | ||
@@ -1450,6 +1450,6 @@ tabIndex: 0, | ||
onFocus: handleFocus, | ||
onPointerMove: handleMove, | ||
onMouseMove: handleMove, | ||
onPointerLeave: handleLeave, | ||
onMouseLeave: handleLeave | ||
onPointermove: handleMove, | ||
onMousemove: handleMove, | ||
onPointerleave: handleLeave, | ||
onMouseleave: handleLeave | ||
}; | ||
@@ -1554,4 +1554,4 @@ return render({ | ||
onClick: this.handleClick, | ||
onKeyUp: this.handleKeyUp, | ||
onKeyPress: this.handleKeyPress | ||
onKeyup: this.handleKeyUp, | ||
onKeypress: this.handleKeyPress | ||
}; | ||
@@ -1558,0 +1558,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e=e||self).headlessui={},e.Vue)}(this,(function(e,t){"use strict";function n(){return(n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e}).apply(this,arguments)}function o(e,t){if(null==e)return{};var n,o,r={},u=Object.keys(e);for(o=0;o<u.length;o++)t.indexOf(n=u[o])>=0||(r[n]=e[n]);return r}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}function u(e,t){if(e in t){for(var n=t[e],o=arguments.length,r=new Array(o>2?o-2:0),l=2;l<o;l++)r[l-2]=arguments[l];return"function"==typeof n?n.apply(void 0,r):n}var a=new Error('Tried to handle "'+e+'" but there is no handler defined. Only defined handlers are: '+Object.keys(t).map((function(e){return'"'+e+'"'})).join(", ")+".");throw Error.captureStackTrace&&Error.captureStackTrace(a,u),a}var l,a;function i(e){var t,r,i=e.visible,c=void 0===i||i,d=e.features,v=void 0===d?l.None:d,f=o(e,["visible","features"]);return c||v&l.Static&&f.props.static?s(f):v&l.RenderStrategy?u(null==(t=f.props.unmount)||t?a.Unmount:a.Hidden,((r={})[a.Unmount]=function(){return null},r[a.Hidden]=function(){return s(n({},f,{props:n({},f.props,{hidden:!0,style:{display:"none"}})}))},r)):s(f)}function s(e){var n=e.attrs,u=e.slots,l=e.slot,a=function(e,t){void 0===t&&(t=[]);for(var n,o=Object.assign({},e),u=function(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return r(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,void 0):void 0}}(e))){n&&(e=n);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}(t);!(n=u()).done;){var l=n.value;l in o&&delete o[l]}return o}(e.props,["unmount","static"]),i=a.as,s=o(a,["as"]),c=null==u.default?void 0:u.default(l);if("template"===i){if(Object.keys(s).length>0||"class"in n){var d=null!=c?c:[],v=d[0];if(d.slice(1).length>0)throw new Error('You should only render 1 child or use the `as="..."` prop');return t.cloneVNode(v,s)}return c}return t.h(i,s,c)}!function(e){e[e.None=0]="None",e[e.RenderStrategy=1]="RenderStrategy",e[e.Static=2]="Static"}(l||(l={})),function(e){e[e.Unmount=0]="Unmount",e[e.Hidden=1]="Hidden"}(a||(a={}));var c,d,v,f=0;function p(){return++f}function b(e,t){var n=t.resolveItems();if(n.length<=0)return null;var o=t.resolveActiveIndex(),r=null!=o?o:-1,u=function(){switch(e.focus){case d.First:return n.findIndex((function(e){return!t.resolveDisabled(e)}));case d.Previous:var o=n.slice().reverse().findIndex((function(e,n,o){return!(-1!==r&&o.length-n-1>=r||t.resolveDisabled(e))}));return-1===o?o:n.length-1-o;case d.Next:return n.findIndex((function(e,n){return!(n<=r||t.resolveDisabled(e))}));case d.Last:var u=n.slice().reverse().findIndex((function(e){return!t.resolveDisabled(e)}));return-1===u?u:n.length-1-u;case d.Specific:return n.findIndex((function(n){return t.resolveId(n)===e.id}));case d.Nothing:return null;default:!function(e){throw new Error("Unexpected object: "+e)}(e)}}();return-1===u?o:u}function m(e,t){if(void 0!==e)return"function"==typeof e?e(t):e}!function(e){e.Space=" ",e.Enter="Enter",e.Escape="Escape",e.Backspace="Backspace",e.ArrowUp="ArrowUp",e.ArrowDown="ArrowDown",e.Home="Home",e.End="End",e.PageUp="PageUp",e.PageDown="PageDown",e.Tab="Tab"}(c||(c={})),function(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"}(d||(d={})),function(e){e[e.Open=0]="Open",e[e.Closed=1]="Closed"}(v||(v={}));var h=Symbol("MenuContext");function y(e){var n=t.inject(h,null);if(null===n){var o=new Error("<"+e+" /> is missing a parent <Menu /> component.");throw Error.captureStackTrace&&Error.captureStackTrace(o,y),o}return n}var x,S=t.defineComponent({props:{as:{type:[Object,String],default:"template"}},setup:function(e,n){var o=n.slots,r=n.attrs,u=t.ref(v.Closed),l=t.ref(null),a=t.ref(null),s=t.ref([]),c=t.ref(""),f=t.ref(null),p={menuState:u,buttonRef:l,itemsRef:a,items:s,searchQuery:c,activeItemIndex:f,closeMenu:function(){u.value=v.Closed,f.value=null},openMenu:function(){return u.value=v.Open},goToItem:function(e,t){var n=b(e===d.Specific?{focus:d.Specific,id:t}:{focus:e},{resolveItems:function(){return s.value},resolveActiveIndex:function(){return f.value},resolveId:function(e){return e.id},resolveDisabled:function(e){return e.dataRef.disabled}});""===c.value&&f.value===n||(c.value="",f.value=n)},search:function(e){c.value+=e;var t=s.value.findIndex((function(e){return e.dataRef.textValue.startsWith(c.value)&&!e.dataRef.disabled}));-1!==t&&t!==f.value&&(f.value=t)},clearSearch:function(){c.value=""},registerItem:function(e,t){s.value.push({id:e,dataRef:t})},unregisterItem:function(e){var t=s.value.slice(),n=null!==f.value?t[f.value]:null,o=t.findIndex((function(t){return t.id===e}));-1!==o&&t.splice(o,1),s.value=t,f.value=o===f.value||null===n?null:t.indexOf(n)}};return t.onMounted((function(){function e(e){var t,n,o,r=e.target,i=document.activeElement;u.value===v.Open&&((null==(t=l.value)?void 0:t.contains(r))||((null==(n=a.value)?void 0:n.contains(r))||p.closeMenu(),i!==document.body&&(null==i?void 0:i.contains(r))||e.defaultPrevented||null==(o=l.value)||o.focus({preventScroll:!0})))}window.addEventListener("mousedown",e),t.onUnmounted((function(){return window.removeEventListener("mousedown",e)}))})),t.provide(h,p),function(){return i({props:e,slot:{open:u.value===v.Open},slots:o,attrs:r})}}}),g=t.defineComponent({props:{disabled:{type:Boolean,default:!1},as:{type:[Object,String],default:"button"}},render:function(){var e,t=y("MenuButton"),o={open:t.menuState.value===v.Open},r={ref:"el",id:this.id,type:"button","aria-haspopup":!0,"aria-controls":null==(e=t.itemsRef.value)?void 0:e.id,"aria-expanded":t.menuState.value===v.Open||void 0,onKeyDown:this.handleKeyDown,onClick:this.handleClick};return i({props:n({},this.$props,r),slot:o,attrs:this.$attrs,slots:this.$slots})},setup:function(e){var n=y("MenuButton");return{id:"headlessui-menu-button-"+p(),el:n.buttonRef,handleKeyDown:function(e){switch(e.key){case c.Space:case c.Enter:case c.ArrowDown:e.preventDefault(),n.openMenu(),t.nextTick((function(){var e;null==(e=n.itemsRef.value)||e.focus({preventScroll:!0}),n.goToItem(d.First)}));break;case c.ArrowUp:e.preventDefault(),n.openMenu(),t.nextTick((function(){var e;null==(e=n.itemsRef.value)||e.focus({preventScroll:!0}),n.goToItem(d.Last)}))}},handleClick:function(o){var r;e.disabled||(n.menuState.value===v.Open?(n.closeMenu(),t.nextTick((function(){var e;return null==(e=n.buttonRef.value)?void 0:e.focus({preventScroll:!0})}))):(o.preventDefault(),n.openMenu(),r=function(){var e;return null==(e=n.itemsRef.value)?void 0:e.focus({preventScroll:!0})},requestAnimationFrame((function(){return requestAnimationFrame(r)}))))}}}}),w=t.defineComponent({props:{as:{type:[Object,String],default:"div"},static:{type:Boolean,default:!1},unmount:{type:Boolean,default:!0}},render:function(){var e,t,o=y("MenuItems"),r={open:o.menuState.value===v.Open},u={"aria-activedescendant":null===o.activeItemIndex.value||null==(e=o.items.value[o.activeItemIndex.value])?void 0:e.id,"aria-labelledby":null==(t=o.buttonRef.value)?void 0:t.id,id:this.id,onKeyDown:this.handleKeyDown,role:"menu",tabIndex:0,ref:"el"};return i({props:n({},this.$props,u),slot:r,attrs:this.$attrs,slots:this.$slots,features:l.RenderStrategy|l.Static,visible:r.open})},setup:function(){var e=y("MenuItems"),n="headlessui-menu-items-"+p(),o=t.ref(null);return t.watchEffect((function(){var t=e.itemsRef.value;if(t&&e.menuState.value===v.Open)for(var n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:function(e){return"menuitem"===e.getAttribute("role")?NodeFilter.FILTER_REJECT:e.hasAttribute("role")?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT}});n.nextNode();)n.currentNode.setAttribute("role","none")})),{id:n,el:e.itemsRef,handleKeyDown:function(n){switch(o.value&&clearTimeout(o.value),n.key){case c.Space:if(""!==e.searchQuery.value)return n.preventDefault(),e.search(n.key);case c.Enter:var r;n.preventDefault(),null!==e.activeItemIndex.value&&(null==(r=document.getElementById(e.items.value[e.activeItemIndex.value].id))||r.click()),e.closeMenu(),t.nextTick((function(){var t;return null==(t=e.buttonRef.value)?void 0:t.focus({preventScroll:!0})}));break;case c.ArrowDown:return n.preventDefault(),e.goToItem(d.Next);case c.ArrowUp:return n.preventDefault(),e.goToItem(d.Previous);case c.Home:case c.PageUp:return n.preventDefault(),e.goToItem(d.First);case c.End:case c.PageDown:return n.preventDefault(),e.goToItem(d.Last);case c.Escape:n.preventDefault(),e.closeMenu(),t.nextTick((function(){var t;return null==(t=e.buttonRef.value)?void 0:t.focus({preventScroll:!0})}));break;case c.Tab:return n.preventDefault();default:1===n.key.length&&(e.search(n.key),o.value=setTimeout((function(){return e.clearSearch()}),350))}}}}}),O=t.defineComponent({props:{as:{type:[Object,String],default:"template"},disabled:{type:Boolean,default:!1},class:{type:[String,Function],required:!1},className:{type:[String,Function],required:!1}},setup:function(e,o){var r=o.slots,u=o.attrs,l=y("MenuItem"),a="headlessui-menu-item-"+p(),s=e.disabled,c=e.className,f=void 0===c?e.class:c,b=t.computed((function(){return null!==l.activeItemIndex.value&&l.items.value[l.activeItemIndex.value].id===a})),h=t.ref({disabled:s,textValue:""});function x(e){if(s)return e.preventDefault();l.closeMenu(),t.nextTick((function(){var e;return null==(e=l.buttonRef.value)?void 0:e.focus({preventScroll:!0})}))}function S(){if(s)return l.goToItem(d.Nothing);l.goToItem(d.Specific,a)}function g(){s||b.value||l.goToItem(d.Specific,a)}function w(){s||b.value&&l.goToItem(d.Nothing)}return t.onMounted((function(){var e,t,n=null==(e=document.getElementById(a))||null==(t=e.textContent)?void 0:t.toLowerCase().trim();void 0!==n&&(h.value.textValue=n)})),t.onMounted((function(){return l.registerItem(a,h)})),t.onUnmounted((function(){return l.unregisterItem(a)})),t.watchEffect((function(){l.menuState.value===v.Open&&b.value&&t.nextTick((function(){var e;return null==(e=document.getElementById(a))||null==e.scrollIntoView?void 0:e.scrollIntoView({block:"nearest"})}))})),function(){var t={active:b.value,disabled:s},o={id:a,role:"menuitem",tabIndex:-1,class:m(f,t),"aria-disabled":!0===s||void 0,onClick:x,onFocus:S,onPointerMove:g,onMouseMove:g,onPointerLeave:w,onMouseLeave:w};return i({props:n({},e,o),slot:t,attrs:u,slots:r})}}});!function(e){e[e.Open=0]="Open",e[e.Closed=1]="Closed"}(x||(x={}));var I=Symbol("ListboxContext");function k(e){var n=t.inject(I,null);if(null===n){var o=new Error("<"+e+" /> is missing a parent <Listbox /> component.");throw Error.captureStackTrace&&Error.captureStackTrace(o,k),o}return n}var T=t.defineComponent({name:"Listbox",emits:["update:modelValue"],props:{as:{type:[Object,String],default:"template"},disabled:{type:[Boolean],default:!1},modelValue:{type:[Object,String,Number,Boolean],default:null}},setup:function(e,n){var r=n.slots,u=n.attrs,l=n.emit,a=e.disabled,s=o(e,["modelValue","disabled"]),c=t.ref(x.Closed),v=t.ref(null),f=t.ref(null),p=t.ref(null),m=t.ref([]),h=t.ref(""),y=t.ref(null),S=t.computed((function(){return e.modelValue})),g={listboxState:c,value:S,labelRef:v,buttonRef:f,optionsRef:p,disabled:a,options:m,searchQuery:h,activeOptionIndex:y,closeListbox:function(){a||c.value!==x.Closed&&(c.value=x.Closed,y.value=null)},openListbox:function(){a||c.value!==x.Open&&(c.value=x.Open)},goToOption:function(e,t){if(!a&&c.value!==x.Closed){var n=b(e===d.Specific?{focus:d.Specific,id:t}:{focus:e},{resolveItems:function(){return m.value},resolveActiveIndex:function(){return y.value},resolveId:function(e){return e.id},resolveDisabled:function(e){return e.dataRef.disabled}});""===h.value&&y.value===n||(h.value="",y.value=n)}},search:function(e){if(!a&&c.value!==x.Closed){h.value+=e;var t=m.value.findIndex((function(e){return!e.dataRef.disabled&&e.dataRef.textValue.startsWith(h.value)}));-1!==t&&t!==y.value&&(y.value=t)}},clearSearch:function(){a||c.value!==x.Closed&&""!==h.value&&(h.value="")},registerOption:function(e,t){m.value.push({id:e,dataRef:t})},unregisterOption:function(e){var t=m.value.slice(),n=null!==y.value?t[y.value]:null,o=t.findIndex((function(t){return t.id===e}));-1!==o&&t.splice(o,1),m.value=t,y.value=o===y.value||null===n?null:t.indexOf(n)},select:function(e){a||l("update:modelValue",e)}};return t.onMounted((function(){function e(e){var t,n,o,r=e.target,u=document.activeElement;c.value===x.Open&&((null==(t=f.value)?void 0:t.contains(r))||((null==(n=p.value)?void 0:n.contains(r))||g.closeListbox(),u!==document.body&&(null==u?void 0:u.contains(r))||e.defaultPrevented||null==(o=f.value)||o.focus({preventScroll:!0})))}window.addEventListener("mousedown",e),t.onUnmounted((function(){return window.removeEventListener("mousedown",e)}))})),t.provide(I,g),function(){return i({props:s,slot:{open:c.value===x.Open,disabled:a},slots:r,attrs:u})}}}),R=t.defineComponent({name:"ListboxLabel",props:{as:{type:[Object,String],default:"label"}},render:function(){var e=k("ListboxLabel"),t={open:e.listboxState.value===x.Open,disabled:e.disabled};return i({props:n({},this.$props,{id:this.id,ref:"el",onClick:this.handleClick}),slot:t,attrs:this.$attrs,slots:this.$slots})},setup:function(){var e=k("ListboxLabel");return{id:"headlessui-listbox-label-"+p(),el:e.labelRef,handleClick:function(){var t;null==(t=e.buttonRef.value)||t.focus({preventScroll:!0})}}}}),L=t.defineComponent({name:"ListboxButton",props:{as:{type:[Object,String],default:"button"}},render:function(){var e,t=k("ListboxButton"),o={open:t.listboxState.value===x.Open,disabled:t.disabled},r={ref:"el",id:this.id,type:"button","aria-haspopup":!0,"aria-controls":null==(e=t.optionsRef.value)?void 0:e.id,"aria-expanded":t.listboxState.value===x.Open||void 0,"aria-labelledby":t.labelRef.value?[t.labelRef.value.id,this.id].join(" "):void 0,disabled:t.disabled,onKeyDown:this.handleKeyDown,onClick:this.handleClick};return i({props:n({},this.$props,r),slot:o,attrs:this.$attrs,slots:this.$slots})},setup:function(){var e=k("ListboxButton");return{id:"headlessui-listbox-button-"+p(),el:e.buttonRef,handleKeyDown:function(n){switch(n.key){case c.Space:case c.Enter:case c.ArrowDown:n.preventDefault(),e.openListbox(),t.nextTick((function(){var t;null==(t=e.optionsRef.value)||t.focus({preventScroll:!0}),e.value.value||e.goToOption(d.First)}));break;case c.ArrowUp:n.preventDefault(),e.openListbox(),t.nextTick((function(){var t;null==(t=e.optionsRef.value)||t.focus({preventScroll:!0}),e.value.value||e.goToOption(d.Last)}))}},handleClick:function(n){var o;e.disabled||(e.listboxState.value===x.Open?(e.closeListbox(),t.nextTick((function(){var t;return null==(t=e.buttonRef.value)?void 0:t.focus({preventScroll:!0})}))):(n.preventDefault(),e.openListbox(),o=function(){var t;return null==(t=e.optionsRef.value)?void 0:t.focus({preventScroll:!0})},requestAnimationFrame((function(){return requestAnimationFrame(o)}))))}}}}),D=t.defineComponent({name:"ListboxOptions",props:{as:{type:[Object,String],default:"ul"},static:{type:Boolean,default:!1},unmount:{type:Boolean,default:!0}},render:function(){var e,t,o,r,u=k("ListboxOptions"),a={open:u.listboxState.value===x.Open},s={"aria-activedescendant":null===u.activeOptionIndex.value||null==(e=u.options.value[u.activeOptionIndex.value])?void 0:e.id,"aria-labelledby":null!=(t=null==(o=u.labelRef.value)?void 0:o.id)?t:null==(r=u.buttonRef.value)?void 0:r.id,id:this.id,onKeyDown:this.handleKeyDown,role:"listbox",tabIndex:0,ref:"el"};return i({props:n({},this.$props,s),slot:a,attrs:this.$attrs,slots:this.$slots,features:l.RenderStrategy|l.Static,visible:a.open})},setup:function(){var e=k("ListboxOptions"),n="headlessui-listbox-options-"+p(),o=t.ref(null);return{id:n,el:e.optionsRef,handleKeyDown:function(n){switch(o.value&&clearTimeout(o.value),n.key){case c.Space:if(""!==e.searchQuery.value)return n.preventDefault(),e.search(n.key);case c.Enter:n.preventDefault(),null!==e.activeOptionIndex.value&&e.select(e.options.value[e.activeOptionIndex.value].dataRef.value),e.closeListbox(),t.nextTick((function(){var t;return null==(t=e.buttonRef.value)?void 0:t.focus({preventScroll:!0})}));break;case c.ArrowDown:return n.preventDefault(),e.goToOption(d.Next);case c.ArrowUp:return n.preventDefault(),e.goToOption(d.Previous);case c.Home:case c.PageUp:return n.preventDefault(),e.goToOption(d.First);case c.End:case c.PageDown:return n.preventDefault(),e.goToOption(d.Last);case c.Escape:n.preventDefault(),e.closeListbox(),t.nextTick((function(){var t;return null==(t=e.buttonRef.value)?void 0:t.focus({preventScroll:!0})}));break;case c.Tab:return n.preventDefault();default:1===n.key.length&&(e.search(n.key),o.value=setTimeout((function(){return e.clearSearch()}),350))}}}}}),E=t.defineComponent({name:"ListboxOption",props:{as:{type:[Object,String],default:"li"},value:{type:[Object,String],default:null},disabled:{type:Boolean,default:!1},class:{type:[String,Function],required:!1},className:{type:[String,Function],required:!1}},setup:function(e,o){var r=o.slots,u=o.attrs,l=k("ListboxOption"),a="headlessui-listbox-option-"+p(),s=e.disabled,c=e.className,v=void 0===c?e.class:c,f=e.value,b=t.computed((function(){return null!==l.activeOptionIndex.value&&l.options.value[l.activeOptionIndex.value].id===a})),h=t.computed((function(){return t.toRaw(l.value.value)===t.toRaw(f)})),y=t.ref({disabled:s,value:f,textValue:""});function S(e){if(s)return e.preventDefault();l.select(f),l.closeListbox(),t.nextTick((function(){var e;return null==(e=l.buttonRef.value)?void 0:e.focus({preventScroll:!0})}))}function g(){if(s)return l.goToOption(d.Nothing);l.goToOption(d.Specific,a)}function w(){s||b.value||l.goToOption(d.Specific,a)}function O(){s||b.value&&l.goToOption(d.Nothing)}return t.onMounted((function(){var e,t,n=null==(e=document.getElementById(a))||null==(t=e.textContent)?void 0:t.toLowerCase().trim();void 0!==n&&(y.value.textValue=n)})),t.onMounted((function(){return l.registerOption(a,y)})),t.onUnmounted((function(){return l.unregisterOption(a)})),t.onMounted((function(){t.watch([l.listboxState,h],(function(){var e;l.listboxState.value===x.Open&&h.value&&(l.goToOption(d.Specific,a),null==(e=document.getElementById(a))||null==e.focus||e.focus())}),{immediate:!0})})),t.watchEffect((function(){l.listboxState.value===x.Open&&b.value&&t.nextTick((function(){var e;return null==(e=document.getElementById(a))||null==e.scrollIntoView?void 0:e.scrollIntoView({block:"nearest"})}))})),function(){var t={active:b.value,selected:h.value,disabled:s},o={id:a,role:"option",tabIndex:-1,class:m(v,t),"aria-disabled":!0===s||void 0,"aria-selected":!0===h.value?h.value:void 0,onClick:S,onFocus:g,onPointerMove:w,onMouseMove:w,onPointerLeave:O,onMouseLeave:O};return i({props:n({},e,o),slot:t,attrs:u,slots:r})}}}),C=Symbol("GroupContext");function M(e){var n=t.inject(C,null);if(null===n){var o=new Error("<"+e+" /> is missing a parent <SwitchGroup /> component.");throw Error.captureStackTrace&&Error.captureStackTrace(o,M),o}return n}var j=t.defineComponent({name:"SwitchGroup",props:{as:{type:[Object,String],default:"template"}},setup:function(e,n){var o=n.slots,r=n.attrs,u=t.ref(null),l=t.ref(null);return t.provide(C,{switchRef:u,labelRef:l}),function(){return i({props:e,slot:{},slots:o,attrs:r})}}}),N=t.defineComponent({name:"Switch",emits:["update:modelValue"],props:{as:{type:[Object,String],default:"button"},modelValue:{type:[Object,Boolean],default:null},class:{type:[String,Function],required:!1},className:{type:[String,Function],required:!1}},render:function(){var e=t.inject(C,null),o=this.$props,r=o.className,u=void 0===r?o.class:r,l=t.computed((function(){var t;return null==e||null==(t=e.labelRef.value)?void 0:t.id})),a={checked:this.$props.modelValue},s={id:this.id,ref:null===e?void 0:e.switchRef,role:"switch",tabIndex:0,class:m(u,a),"aria-checked":this.$props.modelValue,"aria-labelledby":l.value,onClick:this.handleClick,onKeyUp:this.handleKeyUp,onKeyPress:this.handleKeyPress};return"button"===this.$props.as&&Object.assign(s,{type:"button"}),i({props:n({},this.$props,s),slot:a,attrs:this.$attrs,slots:this.$slots})},setup:function(e,n){var o=n.emit,r=t.inject(C,null);function u(){o("update:modelValue",!e.modelValue)}return{id:"headlessui-switch-"+p(),el:null==r?void 0:r.switchRef,handleClick:function(e){e.preventDefault(),u()},handleKeyUp:function(e){e.key!==c.Tab&&e.preventDefault(),e.key===c.Space&&u()},handleKeyPress:function(e){e.preventDefault()}}}}),A=t.defineComponent({name:"SwitchLabel",props:{as:{type:[Object,String],default:"label"}},render:function(){return i({props:n({},this.$props,{id:this.id,ref:"el",onClick:this.handleClick}),slot:{},attrs:this.$attrs,slots:this.$slots})},setup:function(){var e=M("SwitchLabel");return{id:"headlessui-switch-label-"+p(),el:e.labelRef,handleClick:function(){var t,n;null==(t=e.switchRef.value)||t.click(),null==(n=e.switchRef.value)||n.focus({preventScroll:!0})}}}});e.Listbox=T,e.ListboxButton=L,e.ListboxLabel=R,e.ListboxOption=E,e.ListboxOptions=D,e.Menu=S,e.MenuButton=g,e.MenuItem=O,e.MenuItems=w,e.Switch=N,e.SwitchGroup=j,e.SwitchLabel=A,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e=e||self).headlessui={},e.Vue)}(this,(function(e,t){"use strict";function n(){return(n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e}).apply(this,arguments)}function o(e,t){if(null==e)return{};var n,o,r={},l=Object.keys(e);for(o=0;o<l.length;o++)t.indexOf(n=l[o])>=0||(r[n]=e[n]);return r}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}function l(e,t){if(e in t){for(var n=t[e],o=arguments.length,r=new Array(o>2?o-2:0),u=2;u<o;u++)r[u-2]=arguments[u];return"function"==typeof n?n.apply(void 0,r):n}var a=new Error('Tried to handle "'+e+'" but there is no handler defined. Only defined handlers are: '+Object.keys(t).map((function(e){return'"'+e+'"'})).join(", ")+".");throw Error.captureStackTrace&&Error.captureStackTrace(a,l),a}var u,a;function i(e){var t,r,i=e.visible,c=void 0===i||i,d=e.features,v=void 0===d?u.None:d,f=o(e,["visible","features"]);return c||v&u.Static&&f.props.static?s(f):v&u.RenderStrategy?l(null==(t=f.props.unmount)||t?a.Unmount:a.Hidden,((r={})[a.Unmount]=function(){return null},r[a.Hidden]=function(){return s(n({},f,{props:n({},f.props,{hidden:!0,style:{display:"none"}})}))},r)):s(f)}function s(e){var n=e.attrs,l=e.slots,u=e.slot,a=function(e,t){void 0===t&&(t=[]);for(var n,o=Object.assign({},e),l=function(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return r(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,void 0):void 0}}(e))){n&&(e=n);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}(t);!(n=l()).done;){var u=n.value;u in o&&delete o[u]}return o}(e.props,["unmount","static"]),i=a.as,s=o(a,["as"]),c=null==l.default?void 0:l.default(u);if("template"===i){if(Object.keys(s).length>0||"class"in n){var d=null!=c?c:[],v=d[0];if(d.slice(1).length>0)throw new Error('You should only render 1 child or use the `as="..."` prop');return t.cloneVNode(v,s)}return c}return t.h(i,s,c)}!function(e){e[e.None=0]="None",e[e.RenderStrategy=1]="RenderStrategy",e[e.Static=2]="Static"}(u||(u={})),function(e){e[e.Unmount=0]="Unmount",e[e.Hidden=1]="Hidden"}(a||(a={}));var c,d,v,f=0;function p(){return++f}function b(e,t){var n=t.resolveItems();if(n.length<=0)return null;var o=t.resolveActiveIndex(),r=null!=o?o:-1,l=function(){switch(e.focus){case d.First:return n.findIndex((function(e){return!t.resolveDisabled(e)}));case d.Previous:var o=n.slice().reverse().findIndex((function(e,n,o){return!(-1!==r&&o.length-n-1>=r||t.resolveDisabled(e))}));return-1===o?o:n.length-1-o;case d.Next:return n.findIndex((function(e,n){return!(n<=r||t.resolveDisabled(e))}));case d.Last:var l=n.slice().reverse().findIndex((function(e){return!t.resolveDisabled(e)}));return-1===l?l:n.length-1-l;case d.Specific:return n.findIndex((function(n){return t.resolveId(n)===e.id}));case d.Nothing:return null;default:!function(e){throw new Error("Unexpected object: "+e)}(e)}}();return-1===l?o:l}function m(e,t){if(void 0!==e)return"function"==typeof e?e(t):e}!function(e){e.Space=" ",e.Enter="Enter",e.Escape="Escape",e.Backspace="Backspace",e.ArrowUp="ArrowUp",e.ArrowDown="ArrowDown",e.Home="Home",e.End="End",e.PageUp="PageUp",e.PageDown="PageDown",e.Tab="Tab"}(c||(c={})),function(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"}(d||(d={})),function(e){e[e.Open=0]="Open",e[e.Closed=1]="Closed"}(v||(v={}));var h=Symbol("MenuContext");function y(e){var n=t.inject(h,null);if(null===n){var o=new Error("<"+e+" /> is missing a parent <Menu /> component.");throw Error.captureStackTrace&&Error.captureStackTrace(o,y),o}return n}var x,S=t.defineComponent({props:{as:{type:[Object,String],default:"template"}},setup:function(e,n){var o=n.slots,r=n.attrs,l=t.ref(v.Closed),u=t.ref(null),a=t.ref(null),s=t.ref([]),c=t.ref(""),f=t.ref(null),p={menuState:l,buttonRef:u,itemsRef:a,items:s,searchQuery:c,activeItemIndex:f,closeMenu:function(){l.value=v.Closed,f.value=null},openMenu:function(){return l.value=v.Open},goToItem:function(e,t){var n=b(e===d.Specific?{focus:d.Specific,id:t}:{focus:e},{resolveItems:function(){return s.value},resolveActiveIndex:function(){return f.value},resolveId:function(e){return e.id},resolveDisabled:function(e){return e.dataRef.disabled}});""===c.value&&f.value===n||(c.value="",f.value=n)},search:function(e){c.value+=e;var t=s.value.findIndex((function(e){return e.dataRef.textValue.startsWith(c.value)&&!e.dataRef.disabled}));-1!==t&&t!==f.value&&(f.value=t)},clearSearch:function(){c.value=""},registerItem:function(e,t){s.value.push({id:e,dataRef:t})},unregisterItem:function(e){var t=s.value.slice(),n=null!==f.value?t[f.value]:null,o=t.findIndex((function(t){return t.id===e}));-1!==o&&t.splice(o,1),s.value=t,f.value=o===f.value||null===n?null:t.indexOf(n)}};return t.onMounted((function(){function e(e){var t,n,o,r=e.target,i=document.activeElement;l.value===v.Open&&((null==(t=u.value)?void 0:t.contains(r))||((null==(n=a.value)?void 0:n.contains(r))||p.closeMenu(),i!==document.body&&(null==i?void 0:i.contains(r))||e.defaultPrevented||null==(o=u.value)||o.focus({preventScroll:!0})))}window.addEventListener("mousedown",e),t.onUnmounted((function(){return window.removeEventListener("mousedown",e)}))})),t.provide(h,p),function(){return i({props:e,slot:{open:l.value===v.Open},slots:o,attrs:r})}}}),g=t.defineComponent({props:{disabled:{type:Boolean,default:!1},as:{type:[Object,String],default:"button"}},render:function(){var e,t=y("MenuButton"),o={open:t.menuState.value===v.Open},r={ref:"el",id:this.id,type:"button","aria-haspopup":!0,"aria-controls":null==(e=t.itemsRef.value)?void 0:e.id,"aria-expanded":t.menuState.value===v.Open||void 0,onKeydown:this.handleKeyDown,onClick:this.handleClick};return i({props:n({},this.$props,r),slot:o,attrs:this.$attrs,slots:this.$slots})},setup:function(e){var n=y("MenuButton");return{id:"headlessui-menu-button-"+p(),el:n.buttonRef,handleKeyDown:function(e){switch(e.key){case c.Space:case c.Enter:case c.ArrowDown:e.preventDefault(),n.openMenu(),t.nextTick((function(){var e;null==(e=n.itemsRef.value)||e.focus({preventScroll:!0}),n.goToItem(d.First)}));break;case c.ArrowUp:e.preventDefault(),n.openMenu(),t.nextTick((function(){var e;null==(e=n.itemsRef.value)||e.focus({preventScroll:!0}),n.goToItem(d.Last)}))}},handleClick:function(o){var r;e.disabled||(n.menuState.value===v.Open?(n.closeMenu(),t.nextTick((function(){var e;return null==(e=n.buttonRef.value)?void 0:e.focus({preventScroll:!0})}))):(o.preventDefault(),n.openMenu(),r=function(){var e;return null==(e=n.itemsRef.value)?void 0:e.focus({preventScroll:!0})},requestAnimationFrame((function(){return requestAnimationFrame(r)}))))}}}}),w=t.defineComponent({props:{as:{type:[Object,String],default:"div"},static:{type:Boolean,default:!1},unmount:{type:Boolean,default:!0}},render:function(){var e,t,o=y("MenuItems"),r={open:o.menuState.value===v.Open},l={"aria-activedescendant":null===o.activeItemIndex.value||null==(e=o.items.value[o.activeItemIndex.value])?void 0:e.id,"aria-labelledby":null==(t=o.buttonRef.value)?void 0:t.id,id:this.id,onKeydown:this.handleKeyDown,role:"menu",tabIndex:0,ref:"el"};return i({props:n({},this.$props,l),slot:r,attrs:this.$attrs,slots:this.$slots,features:u.RenderStrategy|u.Static,visible:r.open})},setup:function(){var e=y("MenuItems"),n="headlessui-menu-items-"+p(),o=t.ref(null);return t.watchEffect((function(){var t=e.itemsRef.value;if(t&&e.menuState.value===v.Open)for(var n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:function(e){return"menuitem"===e.getAttribute("role")?NodeFilter.FILTER_REJECT:e.hasAttribute("role")?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT}});n.nextNode();)n.currentNode.setAttribute("role","none")})),{id:n,el:e.itemsRef,handleKeyDown:function(n){switch(o.value&&clearTimeout(o.value),n.key){case c.Space:if(""!==e.searchQuery.value)return n.preventDefault(),e.search(n.key);case c.Enter:var r;n.preventDefault(),null!==e.activeItemIndex.value&&(null==(r=document.getElementById(e.items.value[e.activeItemIndex.value].id))||r.click()),e.closeMenu(),t.nextTick((function(){var t;return null==(t=e.buttonRef.value)?void 0:t.focus({preventScroll:!0})}));break;case c.ArrowDown:return n.preventDefault(),e.goToItem(d.Next);case c.ArrowUp:return n.preventDefault(),e.goToItem(d.Previous);case c.Home:case c.PageUp:return n.preventDefault(),e.goToItem(d.First);case c.End:case c.PageDown:return n.preventDefault(),e.goToItem(d.Last);case c.Escape:n.preventDefault(),e.closeMenu(),t.nextTick((function(){var t;return null==(t=e.buttonRef.value)?void 0:t.focus({preventScroll:!0})}));break;case c.Tab:return n.preventDefault();default:1===n.key.length&&(e.search(n.key),o.value=setTimeout((function(){return e.clearSearch()}),350))}}}}}),O=t.defineComponent({props:{as:{type:[Object,String],default:"template"},disabled:{type:Boolean,default:!1},class:{type:[String,Function],required:!1},className:{type:[String,Function],required:!1}},setup:function(e,o){var r=o.slots,l=o.attrs,u=y("MenuItem"),a="headlessui-menu-item-"+p(),s=e.disabled,c=e.className,f=void 0===c?e.class:c,b=t.computed((function(){return null!==u.activeItemIndex.value&&u.items.value[u.activeItemIndex.value].id===a})),h=t.ref({disabled:s,textValue:""});function x(e){if(s)return e.preventDefault();u.closeMenu(),t.nextTick((function(){var e;return null==(e=u.buttonRef.value)?void 0:e.focus({preventScroll:!0})}))}function S(){if(s)return u.goToItem(d.Nothing);u.goToItem(d.Specific,a)}function g(){s||b.value||u.goToItem(d.Specific,a)}function w(){s||b.value&&u.goToItem(d.Nothing)}return t.onMounted((function(){var e,t,n=null==(e=document.getElementById(a))||null==(t=e.textContent)?void 0:t.toLowerCase().trim();void 0!==n&&(h.value.textValue=n)})),t.onMounted((function(){return u.registerItem(a,h)})),t.onUnmounted((function(){return u.unregisterItem(a)})),t.watchEffect((function(){u.menuState.value===v.Open&&b.value&&t.nextTick((function(){var e;return null==(e=document.getElementById(a))||null==e.scrollIntoView?void 0:e.scrollIntoView({block:"nearest"})}))})),function(){var t={active:b.value,disabled:s},o={id:a,role:"menuitem",tabIndex:-1,class:m(f,t),"aria-disabled":!0===s||void 0,onClick:x,onFocus:S,onPointermove:g,onMousemove:g,onPointerleave:w,onMouseleave:w};return i({props:n({},e,o),slot:t,attrs:l,slots:r})}}});!function(e){e[e.Open=0]="Open",e[e.Closed=1]="Closed"}(x||(x={}));var I=Symbol("ListboxContext");function k(e){var n=t.inject(I,null);if(null===n){var o=new Error("<"+e+" /> is missing a parent <Listbox /> component.");throw Error.captureStackTrace&&Error.captureStackTrace(o,k),o}return n}var T=t.defineComponent({name:"Listbox",emits:["update:modelValue"],props:{as:{type:[Object,String],default:"template"},disabled:{type:[Boolean],default:!1},modelValue:{type:[Object,String,Number,Boolean],default:null}},setup:function(e,n){var r=n.slots,l=n.attrs,u=n.emit,a=e.disabled,s=o(e,["modelValue","disabled"]),c=t.ref(x.Closed),v=t.ref(null),f=t.ref(null),p=t.ref(null),m=t.ref([]),h=t.ref(""),y=t.ref(null),S=t.computed((function(){return e.modelValue})),g={listboxState:c,value:S,labelRef:v,buttonRef:f,optionsRef:p,disabled:a,options:m,searchQuery:h,activeOptionIndex:y,closeListbox:function(){a||c.value!==x.Closed&&(c.value=x.Closed,y.value=null)},openListbox:function(){a||c.value!==x.Open&&(c.value=x.Open)},goToOption:function(e,t){if(!a&&c.value!==x.Closed){var n=b(e===d.Specific?{focus:d.Specific,id:t}:{focus:e},{resolveItems:function(){return m.value},resolveActiveIndex:function(){return y.value},resolveId:function(e){return e.id},resolveDisabled:function(e){return e.dataRef.disabled}});""===h.value&&y.value===n||(h.value="",y.value=n)}},search:function(e){if(!a&&c.value!==x.Closed){h.value+=e;var t=m.value.findIndex((function(e){return!e.dataRef.disabled&&e.dataRef.textValue.startsWith(h.value)}));-1!==t&&t!==y.value&&(y.value=t)}},clearSearch:function(){a||c.value!==x.Closed&&""!==h.value&&(h.value="")},registerOption:function(e,t){m.value.push({id:e,dataRef:t})},unregisterOption:function(e){var t=m.value.slice(),n=null!==y.value?t[y.value]:null,o=t.findIndex((function(t){return t.id===e}));-1!==o&&t.splice(o,1),m.value=t,y.value=o===y.value||null===n?null:t.indexOf(n)},select:function(e){a||u("update:modelValue",e)}};return t.onMounted((function(){function e(e){var t,n,o,r=e.target,l=document.activeElement;c.value===x.Open&&((null==(t=f.value)?void 0:t.contains(r))||((null==(n=p.value)?void 0:n.contains(r))||g.closeListbox(),l!==document.body&&(null==l?void 0:l.contains(r))||e.defaultPrevented||null==(o=f.value)||o.focus({preventScroll:!0})))}window.addEventListener("mousedown",e),t.onUnmounted((function(){return window.removeEventListener("mousedown",e)}))})),t.provide(I,g),function(){return i({props:s,slot:{open:c.value===x.Open,disabled:a},slots:r,attrs:l})}}}),R=t.defineComponent({name:"ListboxLabel",props:{as:{type:[Object,String],default:"label"}},render:function(){var e=k("ListboxLabel"),t={open:e.listboxState.value===x.Open,disabled:e.disabled};return i({props:n({},this.$props,{id:this.id,ref:"el",onClick:this.handleClick}),slot:t,attrs:this.$attrs,slots:this.$slots})},setup:function(){var e=k("ListboxLabel");return{id:"headlessui-listbox-label-"+p(),el:e.labelRef,handleClick:function(){var t;null==(t=e.buttonRef.value)||t.focus({preventScroll:!0})}}}}),E=t.defineComponent({name:"ListboxButton",props:{as:{type:[Object,String],default:"button"}},render:function(){var e,t=k("ListboxButton"),o={open:t.listboxState.value===x.Open,disabled:t.disabled},r={ref:"el",id:this.id,type:"button","aria-haspopup":!0,"aria-controls":null==(e=t.optionsRef.value)?void 0:e.id,"aria-expanded":t.listboxState.value===x.Open||void 0,"aria-labelledby":t.labelRef.value?[t.labelRef.value.id,this.id].join(" "):void 0,disabled:t.disabled,onKeydown:this.handleKeyDown,onClick:this.handleClick};return i({props:n({},this.$props,r),slot:o,attrs:this.$attrs,slots:this.$slots})},setup:function(){var e=k("ListboxButton");return{id:"headlessui-listbox-button-"+p(),el:e.buttonRef,handleKeyDown:function(n){switch(n.key){case c.Space:case c.Enter:case c.ArrowDown:n.preventDefault(),e.openListbox(),t.nextTick((function(){var t;null==(t=e.optionsRef.value)||t.focus({preventScroll:!0}),e.value.value||e.goToOption(d.First)}));break;case c.ArrowUp:n.preventDefault(),e.openListbox(),t.nextTick((function(){var t;null==(t=e.optionsRef.value)||t.focus({preventScroll:!0}),e.value.value||e.goToOption(d.Last)}))}},handleClick:function(n){var o;e.disabled||(e.listboxState.value===x.Open?(e.closeListbox(),t.nextTick((function(){var t;return null==(t=e.buttonRef.value)?void 0:t.focus({preventScroll:!0})}))):(n.preventDefault(),e.openListbox(),o=function(){var t;return null==(t=e.optionsRef.value)?void 0:t.focus({preventScroll:!0})},requestAnimationFrame((function(){return requestAnimationFrame(o)}))))}}}}),L=t.defineComponent({name:"ListboxOptions",props:{as:{type:[Object,String],default:"ul"},static:{type:Boolean,default:!1},unmount:{type:Boolean,default:!0}},render:function(){var e,t,o,r,l=k("ListboxOptions"),a={open:l.listboxState.value===x.Open},s={"aria-activedescendant":null===l.activeOptionIndex.value||null==(e=l.options.value[l.activeOptionIndex.value])?void 0:e.id,"aria-labelledby":null!=(t=null==(o=l.labelRef.value)?void 0:o.id)?t:null==(r=l.buttonRef.value)?void 0:r.id,id:this.id,onKeydown:this.handleKeyDown,role:"listbox",tabIndex:0,ref:"el"};return i({props:n({},this.$props,s),slot:a,attrs:this.$attrs,slots:this.$slots,features:u.RenderStrategy|u.Static,visible:a.open})},setup:function(){var e=k("ListboxOptions"),n="headlessui-listbox-options-"+p(),o=t.ref(null);return{id:n,el:e.optionsRef,handleKeyDown:function(n){switch(o.value&&clearTimeout(o.value),n.key){case c.Space:if(""!==e.searchQuery.value)return n.preventDefault(),e.search(n.key);case c.Enter:n.preventDefault(),null!==e.activeOptionIndex.value&&e.select(e.options.value[e.activeOptionIndex.value].dataRef.value),e.closeListbox(),t.nextTick((function(){var t;return null==(t=e.buttonRef.value)?void 0:t.focus({preventScroll:!0})}));break;case c.ArrowDown:return n.preventDefault(),e.goToOption(d.Next);case c.ArrowUp:return n.preventDefault(),e.goToOption(d.Previous);case c.Home:case c.PageUp:return n.preventDefault(),e.goToOption(d.First);case c.End:case c.PageDown:return n.preventDefault(),e.goToOption(d.Last);case c.Escape:n.preventDefault(),e.closeListbox(),t.nextTick((function(){var t;return null==(t=e.buttonRef.value)?void 0:t.focus({preventScroll:!0})}));break;case c.Tab:return n.preventDefault();default:1===n.key.length&&(e.search(n.key),o.value=setTimeout((function(){return e.clearSearch()}),350))}}}}}),C=t.defineComponent({name:"ListboxOption",props:{as:{type:[Object,String],default:"li"},value:{type:[Object,String],default:null},disabled:{type:Boolean,default:!1},class:{type:[String,Function],required:!1},className:{type:[String,Function],required:!1}},setup:function(e,o){var r=o.slots,l=o.attrs,u=k("ListboxOption"),a="headlessui-listbox-option-"+p(),s=e.disabled,c=e.className,v=void 0===c?e.class:c,f=e.value,b=t.computed((function(){return null!==u.activeOptionIndex.value&&u.options.value[u.activeOptionIndex.value].id===a})),h=t.computed((function(){return t.toRaw(u.value.value)===t.toRaw(f)})),y=t.ref({disabled:s,value:f,textValue:""});function S(e){if(s)return e.preventDefault();u.select(f),u.closeListbox(),t.nextTick((function(){var e;return null==(e=u.buttonRef.value)?void 0:e.focus({preventScroll:!0})}))}function g(){if(s)return u.goToOption(d.Nothing);u.goToOption(d.Specific,a)}function w(){s||b.value||u.goToOption(d.Specific,a)}function O(){s||b.value&&u.goToOption(d.Nothing)}return t.onMounted((function(){var e,t,n=null==(e=document.getElementById(a))||null==(t=e.textContent)?void 0:t.toLowerCase().trim();void 0!==n&&(y.value.textValue=n)})),t.onMounted((function(){return u.registerOption(a,y)})),t.onUnmounted((function(){return u.unregisterOption(a)})),t.onMounted((function(){t.watch([u.listboxState,h],(function(){var e;u.listboxState.value===x.Open&&h.value&&(u.goToOption(d.Specific,a),null==(e=document.getElementById(a))||null==e.focus||e.focus())}),{immediate:!0})})),t.watchEffect((function(){u.listboxState.value===x.Open&&b.value&&t.nextTick((function(){var e;return null==(e=document.getElementById(a))||null==e.scrollIntoView?void 0:e.scrollIntoView({block:"nearest"})}))})),function(){var t={active:b.value,selected:h.value,disabled:s},o={id:a,role:"option",tabIndex:-1,class:m(v,t),"aria-disabled":!0===s||void 0,"aria-selected":!0===h.value?h.value:void 0,onClick:S,onFocus:g,onPointermove:w,onMousemove:w,onPointerleave:O,onMouseleave:O};return i({props:n({},e,o),slot:t,attrs:l,slots:r})}}}),D=Symbol("GroupContext");function j(e){var n=t.inject(D,null);if(null===n){var o=new Error("<"+e+" /> is missing a parent <SwitchGroup /> component.");throw Error.captureStackTrace&&Error.captureStackTrace(o,j),o}return n}var M=t.defineComponent({name:"SwitchGroup",props:{as:{type:[Object,String],default:"template"}},setup:function(e,n){var o=n.slots,r=n.attrs,l=t.ref(null),u=t.ref(null);return t.provide(D,{switchRef:l,labelRef:u}),function(){return i({props:e,slot:{},slots:o,attrs:r})}}}),N=t.defineComponent({name:"Switch",emits:["update:modelValue"],props:{as:{type:[Object,String],default:"button"},modelValue:{type:[Object,Boolean],default:null},class:{type:[String,Function],required:!1},className:{type:[String,Function],required:!1}},render:function(){var e=t.inject(D,null),o=this.$props,r=o.className,l=void 0===r?o.class:r,u=t.computed((function(){var t;return null==e||null==(t=e.labelRef.value)?void 0:t.id})),a={checked:this.$props.modelValue},s={id:this.id,ref:null===e?void 0:e.switchRef,role:"switch",tabIndex:0,class:m(l,a),"aria-checked":this.$props.modelValue,"aria-labelledby":u.value,onClick:this.handleClick,onKeyup:this.handleKeyUp,onKeypress:this.handleKeyPress};return"button"===this.$props.as&&Object.assign(s,{type:"button"}),i({props:n({},this.$props,s),slot:a,attrs:this.$attrs,slots:this.$slots})},setup:function(e,n){var o=n.emit,r=t.inject(D,null);function l(){o("update:modelValue",!e.modelValue)}return{id:"headlessui-switch-"+p(),el:null==r?void 0:r.switchRef,handleClick:function(e){e.preventDefault(),l()},handleKeyUp:function(e){e.key!==c.Tab&&e.preventDefault(),e.key===c.Space&&l()},handleKeyPress:function(e){e.preventDefault()}}}}),A=t.defineComponent({name:"SwitchLabel",props:{as:{type:[Object,String],default:"label"}},render:function(){return i({props:n({},this.$props,{id:this.id,ref:"el",onClick:this.handleClick}),slot:{},attrs:this.$attrs,slots:this.$slots})},setup:function(){var e=j("SwitchLabel");return{id:"headlessui-switch-label-"+p(),el:e.labelRef,handleClick:function(){var t,n;null==(t=e.switchRef.value)||t.click(),null==(n=e.switchRef.value)||n.focus({preventScroll:!0})}}}});e.Listbox=T,e.ListboxButton=E,e.ListboxLabel=R,e.ListboxOption=C,e.ListboxOptions=L,e.Menu=S,e.MenuButton=g,e.MenuItem=O,e.MenuItems=w,e.Switch=N,e.SwitchGroup=M,e.SwitchLabel=A,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=headlessui.umd.production.min.js.map |
{ | ||
"name": "@headlessui/vue", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"main": "dist/index.js", | ||
@@ -23,3 +23,3 @@ "typings": "dist/index.d.ts", | ||
"scripts": { | ||
"playground": "vite serve examples", | ||
"playground": "vite --config ./vite.config.js serve examples", | ||
"playground:build": "NODE_ENV=production vite build examples", | ||
@@ -33,3 +33,3 @@ "prepublishOnly": "npm run build", | ||
"peerDependencies": { | ||
"vue": "^3.0.0-rc.13" | ||
"vue": "^3.0.0" | ||
}, | ||
@@ -43,5 +43,5 @@ "devDependencies": { | ||
"vite": "^1.0.0-rc.4", | ||
"vue": "^3.0.0-rc.13", | ||
"vue": "^3.0.0", | ||
"vue-router": "^4.0.0-beta.13" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
636823