1import{F as e,J as t,R as s,T as i,ct as n,fn as a,it as l,ut as d,wt as o}from"./A7A7LHMD.js";import{v as r}from"#entry";import{a as c,i as h,o as u,r as p,s as m}from"./RjvxlQoY.js";var g=e({name:"DropdownButton",inheritAttrs:!1,props:{tag:{type:[String,Object],default:"button"},modelValue:{type:String,default:""},ariaOwns:{type:String,required:!0},additionalClickQuery:{type:String,default:""},multiple:{type:Boolean,default:!1},closeOnSelect:{type:Boolean,default:!0},closeOnBlur:{type:Boolean,default:!0},persistentButtonFocus:{type:Boolean,default:!0},initiallyExpanded:{type:Boolean,default:!1}},emits:["input","change","update:modelValue","update:activedescendant","state:toggle","state:show","state:hide"],data(){return{isExpanded:this.initiallyExpanded,selectedIds:[],selectedValues:(this.modelValue?.split?.(",")??[]).filter(Boolean),selectedTexts:[],activedescendant:"",hasChanged:!1,isNavigatingByKeyboard:!1,optionElementsCache:null,ownedListObservers:[],tabbableElementsCache:null,tabbableElementsCacheStamp:0}},computed:{value:{get(){return this.modelValue},set(e){e!==this.modelValue&&(this.$emit("update:modelValue",e),this.$emit("change",e),this.selectedValues=e.split(",").filter(Boolean))}},attrs(){const e=this||{},t=this.$attrs;return{type:"button"===this.tag?"button":null,role:"combobox","aria-haspopup":this.ariaOwns?"listbox":null,"aria-owns":this.ariaOwns,"aria-controls":this.ariaOwns,"aria-expanded":this.isExpanded?.toString(),"aria-activedescendant":this.activedescendant||null,tabindex:0,...this.$attrs||{},onClick:s=>{(t?.onClick)?.(s),s.defaultPrevented||(e.$el.focus({preventScroll:!0}),e.toggleOwnedLists())},onKeydown:s=>{(t?.onKeydown)?.(s),["Tab","Escape","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Enter"," "].includes(s.key)&&(e.isNavigatingByKeyboard=!0),s.defaultPrevented||("Escape"===s.key&&(e.toggleOwnedLists(!1),s.preventDefault(),s.stopPropagation(),document.activeElement!==e.$el&&e.$el.focus?.({preventScroll:!0})),"ArrowUp"!==s.key&&"ArrowLeft"!==s.key||(e.onNavigation(s),s.preventDefault()),"ArrowDown"!==s.key&&"ArrowRight"!==s.key||(e.onNavigation(s),s.preventDefault()),"Enter"===s.key&&(e.onNavigation(s),s.preventDefault())," "===s.key&&(e.onNavigation(s),s.preventDefault()))}}},slotBindings(){return{isExpanded:this.isExpanded,selectedIds:this.selectedIds,selectedValues:this.selectedValues,selectedTexts:this.selectedTexts,activedescendant:this.activedescendant,isNavigatingByKeyboard:this.isNavigatingByKeyboard}}},watch:{ariaOwns(e,t){m(this,this,t||""),c(this,this,e||""),this.$el&&(u(this,t||""),h(this,e||""),this.invalidateOptionElementsCache(),this.isExpanded&&this.observeOwnedLists())},modelValue(e){this.selectedValues=e.split(",").filter(Boolean)},selectedValues(e){const t=new Set(e),s=this.getOptionElements().filter(e=>{const s=e.getAttribute("data-value");return!!s&&t.has(s)});this.selectedIds=s.map(e=>e.id).filter(Boolean),this.selectedTexts=s.map(e=>e.textContent?.trim?.()).filter(e=>!!e)},activedescendant(e){this.$emit("update:activedescendant",e),this.persistentButtonFocus||document.getElementById(e)?.focus?.({preventScroll:!0})},isExpanded:{immediate:!0,handler(e){if(e){this.observeOwnedLists(),this.invalidateOptionElementsCache();const e=new Set(this.selectedValues);this.getOptionElements().forEach(t=>{const s=t.getAttribute("data-value");s&&e.has(s)?t.setAttribute("aria-selected","true"):t.setAttribute("aria-selected","false")})}else this.disconnectOwnedListObservers(),this.activedescendant="",this.isNavigatingByKeyboard=!1,this.hasChanged&&(this.$emit("update:modelValue",this.selectedValues.join(",")),this.$emit("change",this.selectedValues.join(",")),this.hasChanged=!1)}}},created(){c(this,this,this.ariaOwns)},mounted(){p.add(this),h(this,this.ariaOwns);const e=this.getOptionElements().filter(e=>!!e.getAttribute("data-value")&&this.selectedValues?.includes?.(e.getAttribute("data-value")));this.selectedIds=e.map(e=>e.id).filter(Boolean),this.selectedTexts=e.map(e=>e.textContent?.trim?.()).filter(e=>!!e),document.addEventListener("focusout",this.onFocusout,!0)},beforeUnmount(){this.disconnectOwnedListObservers(),m(this,this,this.ariaOwns),p.delete(this),u(this,this.ariaOwns),document.removeEventListener("focusout",this.onFocusout,!0)},methods:{toggleOwnedLists(e){this.isExpanded=e??!this.isExpanded,this.$emit("state:toggle",this.isExpanded),this.isExpanded&&this.$emit("state:sh
1ow",!0),!this.isExpanded&&this.$emit("state:hide",!1)},getOptionElements(){if(this.optionElementsCache)return this.optionElementsCache;const e=globalThis.document;if(!e)return[];const t=this.ariaOwns?.split?.(" ")?.map(t=>e.getElementById(t)).filter(e=>!!e)||[],s=[];return t.forEach(e=>{const t=e?.querySelectorAll?.(".c-dropdown-option")||[];s.push(...t)}),this.optionElementsCache=s,s},invalidateOptionElementsCache(){this.optionElementsCache=null},observeOwnedLists(){this.disconnectOwnedListObservers(),"undefined"!=typeof document&&"undefined"!=typeof MutationObserver&&this.ariaOwns?.split?.(" ")?.map(e=>document.getElementById(e)).filter(e=>!!e).forEach(e=>{const t=new MutationObserver(()=>{this.invalidateOptionElementsCache()});t.observe(e,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["class","id","aria-selected","data-value"]}),this.ownedListObservers.push(t)})},disconnectOwnedListObservers(){this.ownedListObservers.forEach(e=>e.disconnect()),this.ownedListObservers=[],this.invalidateOptionElementsCache()},updateInternalValue(){const e=this.getOptionElements().filter(e=>"true"===e.getAttribute("aria-selected")?.toLowerCase?.()).map(e=>e.getAttribute("data-value")).filter(e=>!!e);this.selectedValues=e,this.$emit("input",this.selectedValues.join(",")),this.isExpanded?this.hasChanged=!0:(this.$emit("update:modelValue",this.selectedValues.join(",")),this.$emit("change",this.selectedValues.join(",")),this.hasChanged=!1)},onNavigation(e){const{isExpanded:t}=this,s=this.getOptionElements();if(!s.length)return;let i=-1;if(this.activedescendant?i=s.findIndex(e=>e?.id===this.activedescendant):this.selectedIds?.[0]&&(i=s.findIndex(e=>e?.id===this.selectedIds?.[0])),this.isNavigatingByKeyboard=!0,"ArrowUp"===e.key||"ArrowLeft"===e.key)if(e.altKey)this.toggleOwnedLists(!1),document.activeElement!==this.$el&&this.$el.focus?.({preventScroll:!0});else{this.toggleOwnedLists(!0);let e=i-1;t||-1===i||(e=i),e<0&&(e=s.length-1),this.activedescendant=s[e]?.id||"";const n=this.activedescendant?document.getElementById(this.activedescendant):null;try{n?.scrollIntoView?.({block:"nearest"})}catch{n?.scrollIntoView?.()}}if("ArrowDown"===e.key||"ArrowRight"===e.key)if(e.altKey)this.toggleOwnedLists(!0);else{this.toggleOwnedLists(!0);let e=i+1;t||-1===i||(e=i),e>=s.length&&(e=0),this.activedescendant=s[e]?.id??"";const n=this.activedescendant?document.getElementById(this.activedescendant):null;try{n?.scrollIntoView?.({block:"nearest"})}catch{n?.scrollIntoView?.()}}if("Enter"===e.key||" "===e.key){if("Enter"===e.key&&this.multiple)return this.toggleOwnedLists(),void(document.activeElement!==this.$el&&this.$el.focus?.({preventScroll:!0}));if(this.isExpanded){if(!this.activedescendant)return void this.toggleOwnedLists(!1);const e=s[i];e&&e.click()}else this.toggleOwnedLists(!0)}},onFocusout(e){if(this.isExpanded){const t=this.$el,s=[t];this.ariaOwns?.split?.(" ")?.forEach(e=>{const t=document.getElementById(e);t&&s.push(t)}),this.additionalClickQuery&&[...document.querySelectorAll(this.additionalClickQuery)].forEach(e=>{e instanceof HTMLElement&&s.push(e)});const i=s.find(t=>t.contains(e.relatedTarget??null));if(i){if(i!==t)if(this.persistentButtonFocus){const s=this.isNavigatingByKeyboard?this.findNextTabbableElement(e):t;s?.focus?.({preventScroll:!0}),s!==t&&(this.activedescendant="",this.closeOnBlur&&this.toggleOwnedLists(!1))}else{const t=e.relatedTarget;this.activedescendant=t?.id?t.id:""}}else this.activedescendant="",this.closeOnBlur&&this.toggleOwnedLists(!1)}},onListClick(e){if(this.multiple&&!this.persistentButtonFocus||this.$el.focus({preventScroll:!0}),this.isNavigatingByKeyboard=!1,e.defaultPrevented)return;let t=e.target;for(;t&&!t.classList.contains("c-dropdown-option-list");){if(t.classList.contains("c-dropdown-option")){if("true"===t.getAttribute("aria-disabled")?.toLowerCase?.())break;if(this.multiple){"true"===t.getAttribute("aria-selected")?.toLowerCase?.()?t.setAttribute("aria-selected","false"):t.setAttribute("aria-selected","true"),this.activedescendant=t.id,this.updateInternalValue();break}
1this.getOptionElements().forEach(e=>e.setAttribute("aria-selected","false")),t.setAttribute("aria-selected","true"),this.updateInternalValue(),this.closeOnSelect&&this.toggleOwnedLists(!1);break}t=t.parentElement}},findNextTabbableElement(e){const t=Date.now();let s=this.tabbableElementsCache;if(!s||t-this.tabbableElementsCacheStamp>100){s=[...document.querySelectorAll('button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"]):not([disabled]), details:not([disabled]), summary:not(:disabled)')].filter(e=>e&&-1!==+e.tabIndex);const e=Math.max(0,...s.map(e=>+e.tabIndex));s.sort((t,s)=>{let i=+t.tabIndex,n=+s.tabIndex;return i===n?0:(0===i&&(i=e+1),0===n&&(n=e+1),i-n)}),this.tabbableElementsCache=s,this.tabbableElementsCacheStamp=t}if(e.target&&e.relatedTarget){const t=this.ariaOwns?.split?.(" ")?.map(e=>document.getElementById(e)).filter(e=>!!e)||[],i=s.indexOf(e.target),n=s.indexOf(e.relatedTarget);if(this.additionalClickQuery&&[...document.querySelectorAll(this.additionalClickQuery)].forEach(e=>{e instanceof HTMLElement&&t.push(e)}),n>i){const e=s.find((e,s)=>!!(s>n&&t.every(t=>!t.contains(e))));if(e)return e}if(n<i){s.reverse();const e=s.find((e,s)=>!!(s>n&&t.every(t=>!t.contains(e))));if(e)return e}}return this.$el}}});var f=Object.assign(r(g,[["render",function(e,r,c,h,u,p){return l(),i(d(e.tag),t({class:"c-dropdown-button"},e.attrs),{default:o(()=>[n(e.$slots,"default",a(s(e.slotBindings)))]),_:3},16)}]]),{__name:"DropdownButton"});export{f as t};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.