@wpmoo/ui 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * Moo UI datepicker.min.js v2.1.0 (https://wpmoo.org/)
2
+ * Moo UI datepicker.min.js v2.1.1 (https://wpmoo.org/)
3
3
  * Copyright 2026 WPMoo Authors
4
4
  * Licensed under MIT (https://github.com/wpmoo-org/ui/blob/main/LICENSE)
5
5
  */
6
6
 
7
- var Q='.moo-ui[data-bs-theme="light"], .moo-ui[data-bs-theme="dark"]',lt="[data-moo-overlay-host]";function dt(e){return e?.nodeType===9?e:e?.ownerDocument?e.ownerDocument:typeof document>"u"?null:document}function ct(e){return!!e?.matches?.(Q)}function ht(e){let t=dt(e);return e?.nodeType===9||e===t?.body?t?.body?.firstElementChild||null:e}function q(e=typeof document>"u"?null:document){let t=ht(e);return t?ct(t)?t:t.closest?.(Q)||null:null}function X(e){return e?Array.from(e.children||[]).find(t=>t.matches?.(lt))||e:null}var I=new WeakMap,V=new WeakMap,M=new WeakMap,y="en",Et=1440*60*1e3,ut=new Date(2026,7,16),C=8;function z(e,t){return e?.nodeType===1&&!!e.matches?.(t)}function c(e,t,i,a,n){t&&(t.addEventListener(i,a,n),e.push({target:t,type:i,handler:a,options:n}))}function E(e){e.forEach(({target:t,type:i,handler:a,options:n})=>{t.removeEventListener(i,a,n)}),e.length=0}function d(e){if(!e)return null;if(e instanceof Date)return Number.isNaN(e.getTime())?null:new Date(e.getFullYear(),e.getMonth(),e.getDate());if(typeof e=="number")return d(new Date(e));let t=String(e).trim(),i=/^(\d{4})-(\d{2})-(\d{2})$/.exec(t);if(i){let a=new Date(Number(i[1]),Number(i[2])-1,Number(i[3]));return a.getFullYear()===Number(i[1])&&a.getMonth()===Number(i[2])-1&&a.getDate()===Number(i[3])?a:null}return null}function Z(e){return String(e).padStart(2,"0")}function f(e){return"".concat(e.getFullYear(),"-").concat(Z(e.getMonth()+1),"-").concat(Z(e.getDate()))}function m(e,t){return!e||!t?0:e.getTime()-t.getTime()}function k(e,t){return!!(e&&t&&f(e)===f(t))}function b(e,t){return new Date(e.getFullYear(),e.getMonth(),e.getDate()+t)}function B(e,t){let i=new Date(e.getFullYear(),e.getMonth()+t,1),a=Math.min(e.getDate(),W(i.getFullYear(),i.getMonth()));return new Date(i.getFullYear(),i.getMonth(),a)}function T(e=y){try{if(typeof Intl<"u"&&typeof Intl.Locale=="function"){let t=new Intl.Locale(e||y),i=t.weekInfo||t.getWeekInfo?.();if(Number.isInteger(i?.firstDay))return i.firstDay%7}}catch{}return 0}function _t(e=y){let t=T(e);return Array.from({length:7},(i,a)=>b(ut,(t+a)%7))}function w(e){return new Date(e.getFullYear(),e.getMonth(),1)}function W(e,t){return new Date(e,t+1,0).getDate()}function ft(e,t,i){return t&&m(e,t)<0?new Date(t):i&&m(e,i)>0?new Date(i):e}function pt(e){if(Array.isArray(e))return e.map(d).filter(Boolean).map(f);if(!e)return[];let t=String(e).trim();if(!t)return[];try{let i=JSON.parse(t);if(Array.isArray(i))return i.map(d).filter(Boolean).map(f)}catch{}return t.split(",").map(d).filter(Boolean).map(f)}function x(e,t=y){return e?new Intl.DateTimeFormat(t||y,{month:"short",day:"numeric",year:"numeric"}).format(e):""}function tt(e,t=y){return new Intl.DateTimeFormat(t||y,{month:"long",year:"numeric"}).format(e)}function $(e,t,i=y){if(e)return t==="yyyy-mm-dd"?f(e):t?x(e,i):new Date(e)}function U(e,t={}){let i=e.dataset||{},a=t.locale||i.datepickerLocale||i.calendarLocale||y,n=d(t.minDate||i.calendarMinDate||i.datepickerMinDate),r=d(t.maxDate||i.calendarMaxDate||i.datepickerMaxDate);return{locale:a,mode:t.mode||i.calendarMode||i.datepickerMode||"single",placeholder:t.placeholder||i.datepickerPlaceholder||"Pick a date",value:t.value||i.calendarValue||i.datepickerValue||"",startValue:t.startValue||i.calendarStartValue||i.datepickerStartValue||"",endValue:t.endValue||i.calendarEndValue||i.datepickerEndValue||"",minDate:n,maxDate:r,disabledDates:pt(t.disabledDates||i.calendarDisabledDates||i.datepickerDisabledDates),captionLayout:t.captionLayout||i.calendarCaptionLayout||"",showPresets:t.showPresets??(i.calendarShowPresets==="true"||i.datepickerShowPresets==="true")}}function g(e,t,i,a={},n=!1){return e.dispatchEvent(new t.CustomEvent(i,{bubbles:!0,cancelable:n,detail:a}))}function K(e,t){e&&(e.value=t||"")}function rt(e,t){e&&(e.value=t||"")}function j(e,t,i){if(i){e.dataset.invalid="true",t.classList.add("is-invalid"),t.setAttribute("aria-invalid","true");return}delete e.dataset.invalid,t.classList.remove("is-invalid"),t.removeAttribute("aria-invalid")}function st(e,t,i){i?.required&&i.checkValidity()&&j(e,t,!1)}function et(e,t,i){return i<t?t:Math.min(Math.max(e,t),i)}function mt(e,t,i){let a=e?.ownerDocument?.defaultView||window,n=e?a.getComputedStyle(e).getPropertyValue(t).trim():"",r=Number.parseFloat(n);if(!Number.isFinite(r))return i;if(n.endsWith("rem")){let s=e.ownerDocument.documentElement,_=Number.parseFloat(a.getComputedStyle(s).fontSize);return Number.isFinite(_)?r*_:i}if(n.endsWith("em")){let s=Number.parseFloat(a.getComputedStyle(e).fontSize);return Number.isFinite(s)?r*s:i}return Number.isFinite(r)?r:i}function O(e,t){return!!(t&&(e._element.contains(t)||e._popover.contains(t)))}function it(e){let i=q(e._trigger)?.getAttribute("data-bs-theme")||null,a=e._document.defaultView?.getComputedStyle(e._trigger).direction;i?e._popover.setAttribute("data-bs-theme",i):e._popover.removeAttribute("data-bs-theme"),a==="ltr"||a==="rtl"?e._popover.setAttribute("dir",a):e._popover.removeAttribute("dir")}function gt(e){let t=e._popover,i=q(e._trigger),a=X(i)||e._document.body||e._document.documentElement;if(a){if(e._popoverPortal?.portal===a&&t.parentElement===a){it(e);return}R(e),e._popoverPortal={parent:t.parentNode,nextSibling:t.nextSibling,owner:i,portal:a,hadTheme:t.hasAttribute("data-bs-theme"),theme:t.getAttribute("data-bs-theme"),hadDirection:t.hasAttribute("dir"),direction:t.getAttribute("dir")},a.appendChild(t),it(e)}}function R(e){let t=e._popoverPortal;if(!t)return;let i=e._popover;t.owner?.isConnected===!1?i.remove():t.parent?.isConnected?t.nextSibling?.parentNode===t.parent?t.parent.insertBefore(i,t.nextSibling):t.parent.appendChild(i):i.remove(),t.hadTheme?i.setAttribute("data-bs-theme",t.theme):i.removeAttribute("data-bs-theme"),t.hadDirection?i.setAttribute("dir",t.direction):i.removeAttribute("dir"),e._popoverPortal=null}function Dt(e,t,i,a){let n=mt(i,"--moo-datepicker-popover-offset",6),r=getComputedStyle(e).direction;t.style.position="fixed",t.style.inset="auto",t.style.right="auto",t.style.bottom="auto",t.style.maxHeight="",t.style.overflowY="";let s=e.getBoundingClientRect(),_=t.getBoundingClientRect(),S=a.innerWidth,D=a.innerHeight,P=r==="rtl"?s.right-_.width:s.left,Y=et(P,C,S-_.width-C),A=s.bottom+n<=D?D-s.bottom-n-C:0,h=s.top-n-C,l=_.height>A&&h>A,u=l?"top":"bottom",o=Math.max(0,l?h:A),N=Math.min(_.height,o),v=l?s.top-n-N:s.bottom+n;t.style.left="".concat(Math.round(Y),"px"),t.style.top="".concat(Math.round(et(v,C,D-N-C)),"px"),o>0&&(t.style.maxHeight="".concat(Math.floor(o),"px"),t.style.overflowY="auto"),t.dataset.datepickerPlacement=u}function yt(e){e.style.position="",e.style.inset="",e.style.right="",e.style.bottom="",e.style.left="",e.style.top="",e.style.maxHeight="",e.style.overflowY="",delete e.dataset.datepickerPlacement}function ot(e){E(e._floatingListeners),gt(e);let t=()=>{e.isOpen()&&Dt(e._trigger,e._popover,e._element,e._window)};e._positionPopover=t,t(),c(e._floatingListeners,e._window,"resize",t),c(e._floatingListeners,e._window,"scroll",t,!0),c(e._floatingListeners,e._document,"scroll",t,!0)}function F(e){E(e._floatingListeners),e._positionPopover=null,yt(e._popover),R(e)}function wt(e,t){return new Intl.DateTimeFormat(t||y,{month:"short"}).format(new Date(2026,e,1))}function bt(e,t,i){let a=e?e.getFullYear():i.getFullYear()-100,n=t?t.getFullYear():i.getFullYear()+20,r=[];for(let s=a;s<=n;s+=1)r.push(s);return r}function at(e,t,i=""){let a=e.createElement("span");return a.className=i,a.setAttribute("aria-hidden","true"),a.textContent=t,a}var L=class e{static getInstance(t){return t?.nodeType===1&&V.get(t)||null}static getOrCreateInstance(t,i={}){return e.getInstance(t)||new e(t,i)}constructor(t,i={}){if(!z(t,"[data-calendar]"))throw new TypeError("MooCalendar requires a [data-calendar] root element.");let a=V.get(t);if(a)return a;this._element=t,this._document=t.ownerDocument,this._window=this._document.defaultView||window,this._listeners=[],this._disposed=!1,this._config=U(t,i),this._mode=this._config.mode==="range"?"range":"single",this._disabledDates=new Set(this._config.disabledDates),this._selectedDate=d(this._config.value),this._rangeStart=d(this._config.startValue),this._rangeEnd=d(this._config.endValue),this._activeDate=this._nearestEnabledDate(this._rangeStart||this._selectedDate||new Date),this._viewDate=w(this._activeDate),this._captionId=this._element.id?"".concat(this._element.id,"-caption"):"moo-calendar-caption-".concat(Math.random().toString(36).slice(2)),this._labelId=this._element.id?"".concat(this._element.id,"-label"):"moo-calendar-label-".concat(Math.random().toString(36).slice(2)),V.set(t,this),this._bindEvents(),this._render()}dispose(){this._disposed||(this._disposed=!0,E(this._listeners),this._element.replaceChildren(),V.get(this._element)===this&&V.delete(this._element))}getDate(t=void 0){return this._mode==="range"?this.getDates(t):$(this._selectedDate,t,this._config.locale)}getDates(t=void 0){return[$(this._rangeStart,t,this._config.locale),$(this._rangeEnd,t,this._config.locale)]}setDate(t,i={}){if(this._mode!=="single")return!1;let a=d(t);return!a||this._isDisabled(a)?!1:(this._selectedDate=a,this._activeDate=a,this._viewDate=w(a),this._render(),i.emit!==!1&&this._emitChange(!0),!0)}setDates(t,i,a={}){if(this._mode!=="range")return!1;let n=d(t),r=d(i);return n&&this._isDisabled(n)||r&&this._isDisabled(r)?!1:(this._rangeStart=n,this._rangeEnd=r,this._rangeStart&&this._rangeEnd&&m(this._rangeStart,this._rangeEnd)>0&&([this._rangeStart,this._rangeEnd]=[this._rangeEnd,this._rangeStart]),this._activeDate=this._rangeEnd||this._rangeStart||this._activeDate,this._viewDate=w(this._activeDate),this._render(),a.emit!==!1&&this._emitChange(!!(this._rangeStart&&this._rangeEnd)),!0)}clear(t={}){this._selectedDate=null,this._rangeStart=null,this._rangeEnd=null,this._render(),t.emit!==!1&&this._emitChange(!1)}focusActiveDay(){this._dayButton(this._activeDate)?.focus()}_bindEvents(){c(this._listeners,this._element,"click",t=>{let i=t.target,a=i.closest?.("[data-calendar-day]"),n=i.closest?.("[data-calendar-prev]"),r=i.closest?.("[data-calendar-next]"),s=i.closest?.("[data-calendar-preset]");n?this._changeMonth(-1,!0):r?this._changeMonth(1,!0):s?this._selectPreset(s.dataset.calendarPreset):a&&this._selectDate(d(a.dataset.calendarDay),!0)}),c(this._listeners,this._element,"keydown",t=>{t.target.closest?.("[data-calendar-day]")&&this._handleDayKeydown(t)}),c(this._listeners,this._element,"change",t=>{t.target.matches?.("[data-calendar-month]")&&this._setActiveMonth(this._viewDate.getFullYear(),Number(t.target.value),!0),t.target.matches?.("[data-calendar-year]")&&this._setActiveMonth(Number(t.target.value),this._viewDate.getMonth(),!0)})}_emitChange(t){g(this._element,this._window,"change.moo.calendar",{date:this._selectedDate?new Date(this._selectedDate):void 0,value:this._selectedDate?f(this._selectedDate):"",startDate:this._rangeStart?new Date(this._rangeStart):void 0,endDate:this._rangeEnd?new Date(this._rangeEnd):void 0,startValue:this._rangeStart?f(this._rangeStart):"",endValue:this._rangeEnd?f(this._rangeEnd):"",complete:t})}_changeMonth(t,i){let a=w(B(this._viewDate,t));this._setActiveMonth(a.getFullYear(),a.getMonth(),i)}_setActiveMonth(t,i,a=!1){let n=Math.min(this._activeDate.getDate(),W(t,i));this._activeDate=this._nearestEnabledDate(new Date(t,i,n)),this._viewDate=w(this._activeDate),this._render(),a&&this.focusActiveDay()}_selectPreset(t){if(!t)return;let i=new Date,a={today:0,tomorrow:1,"in-3-days":3,"in-a-week":7,"in-2-weeks":14};t in a&&this._selectDate(b(i,a[t]),!0)}_handleDayKeydown(t){let i=t.target.closest?.("[data-calendar-day]"),a=d(i?.dataset?.calendarDay);a&&m(a,this._activeDate)!==0&&(this._activeDate=a);let n={ArrowRight:1,ArrowLeft:-1,ArrowDown:7,ArrowUp:-7},r=null;if(t.key in n)r=b(this._activeDate,n[t.key]);else if(t.key==="Home"){let s=T(this._config.locale),_=(this._activeDate.getDay()-s+7)%7;r=b(this._activeDate,-_)}else if(t.key==="End"){let s=T(this._config.locale),_=(this._activeDate.getDay()-s+7)%7;r=b(this._activeDate,6-_)}else if(t.key==="PageUp")r=B(this._activeDate,-1);else if(t.key==="PageDown")r=B(this._activeDate,1);else if(t.key==="Enter"||t.key===" "||t.key==="Spacebar"){t.preventDefault(),this._selectDate(this._activeDate,!0);return}else return;t.preventDefault(),this._setActiveDate(r,!0,m(r,this._activeDate)<0?-1:1)}_setActiveDate(t,i=!1,a=0){let n=a===0?this._nearestEnabledDate(t):this._nextEnabledDate(t,a);this._activeDate=n,this._viewDate=w(n),this._render(),i&&this.focusActiveDay()}_nextEnabledDate(t,i){let a=d(t);if(!a)return this._activeDate;let n=i<0?-1:1;for(let r=0;r<366&&!(this._config.minDate&&m(a,this._config.minDate)<0||this._config.maxDate&&m(a,this._config.maxDate)>0);r+=1){if(!this._isDisabled(a))return a;a=b(a,n)}return this._activeDate}_nearestEnabledDate(t){let i=ft(d(t)||new Date,this._config.minDate,this._config.maxDate);if(!this._isDisabled(i))return i;let a=w(i),n=W(a.getFullYear(),a.getMonth());for(let r=1;r<=n;r+=1){let s=new Date(a.getFullYear(),a.getMonth(),r);if(!this._isDisabled(s))return s}return i}_selectDate(t,i){if(!(!t||this._isDisabled(t))){if(this._activeDate=t,this._viewDate=w(t),this._mode==="range"){!this._rangeStart||this._rangeEnd||m(t,this._rangeStart)<0?(this._rangeStart=t,this._rangeEnd=null):this._rangeEnd=t,this._render(),i&&this._emitChange(!!(this._rangeStart&&this._rangeEnd));return}this._selectedDate=t,this._render(),i&&this._emitChange(!0)}}_isDisabled(t){return!t||this._config.minDate&&m(t,this._config.minDate)<0||this._config.maxDate&&m(t,this._config.maxDate)>0?!0:this._disabledDates.has(f(t))}_isSelected(t){return this._mode==="range"?k(t,this._rangeStart)||k(t,this._rangeEnd):k(t,this._selectedDate)}_rangeState(t){return this._mode!=="range"||!this._rangeStart?"":k(t,this._rangeStart)?"start":k(t,this._rangeEnd)?"end":this._rangeStart&&this._rangeEnd&&m(t,this._rangeStart)>0&&m(t,this._rangeEnd)<0?"middle":""}_dayButton(t){return this._element.querySelector('[data-calendar-day="'.concat(f(t),'"]'))}_render(){let t=this._document,i=t.createDocumentFragment(),a=t.createElement("div");a.className="moo-calendar__header";let n=t.createElement("button");n.className="btn btn-ghost btn-icon-sm moo-calendar__nav",n.type="button",n.dataset.calendarPrev="true",n.setAttribute("aria-label","Previous month"),n.appendChild(at(t,"\u2039","moo-calendar__nav-icon"));let r=t.createElement("button");r.className="btn btn-ghost btn-icon-sm moo-calendar__nav",r.type="button",r.dataset.calendarNext="true",r.setAttribute("aria-label","Next month"),r.appendChild(at(t,"\u203A","moo-calendar__nav-icon"));let s=t.createElement("div");if(s.className="moo-calendar__caption",s.id=this._captionId,s.setAttribute("aria-live","polite"),this._config.captionLayout==="dropdown"){let h=t.createElement("select");h.className="moo-calendar__select",h.dataset.calendarMonth="true",h.setAttribute("aria-label","Month");for(let u=0;u<12;u+=1){let o=t.createElement("option");o.value=String(u),o.textContent=wt(u,this._config.locale),o.selected=u===this._viewDate.getMonth(),h.appendChild(o)}let l=t.createElement("select");l.className="moo-calendar__select",l.dataset.calendarYear="true",l.setAttribute("aria-label","Year"),bt(this._config.minDate,this._config.maxDate,this._viewDate).forEach(u=>{let o=t.createElement("option");o.value=String(u),o.textContent=String(u),o.selected=u===this._viewDate.getFullYear(),l.appendChild(o)}),s.append(h,l)}else s.textContent=tt(this._viewDate,this._config.locale);a.append(n,s,r),i.appendChild(a);let _=t.createElement("div");_.id=this._labelId,_.className="visually-hidden",_.textContent=this._element.getAttribute("aria-label")||tt(this._viewDate,this._config.locale),i.appendChild(_);let S=t.createElement("div");S.className="moo-calendar__weekdays",S.setAttribute("role","row"),_t(this._config.locale).forEach(h=>{let l=t.createElement("span");l.className="moo-calendar__weekday",l.setAttribute("role","columnheader"),l.textContent=new Intl.DateTimeFormat(this._config.locale,{weekday:"narrow"}).format(h),S.appendChild(l)});let D=t.createElement("div");D.className="moo-calendar__grid",D.setAttribute("role","grid"),D.setAttribute("aria-labelledby",this._labelId),D.appendChild(S);let P=w(this._viewDate),Y=T(this._config.locale),A=b(P,-((P.getDay()-Y+7)%7));for(let h=0;h<6;h+=1){let l=t.createElement("div");l.className="moo-calendar__week",l.setAttribute("role","row");for(let u=0;u<7;u+=1){let o=b(A,h*7+u),N=f(o),v=t.createElement("div");v.className="moo-calendar__cell",v.setAttribute("role","gridcell");let p=t.createElement("button");p.className="moo-calendar__day",p.type="button",p.dataset.calendarDay=N,p.textContent=String(o.getDate()),p.tabIndex=k(o,this._activeDate)?0:-1,p.setAttribute("aria-label",x(o,this._config.locale));let G=this._isSelected(o);p.dataset.calendarSelected=String(G),v.setAttribute("aria-selected",G?"true":"false"),o.getMonth()!==this._viewDate.getMonth()&&(p.dataset.calendarOutside="true"),k(o,new Date)&&(p.dataset.calendarToday="true",p.setAttribute("aria-current","date"));let J=this._rangeState(o);J&&(p.dataset.calendarRange=J),this._isDisabled(o)&&(p.disabled=!0,p.setAttribute("aria-disabled","true")),v.appendChild(p),l.appendChild(v)}D.appendChild(l)}if(i.appendChild(D),this._config.showPresets){let h=t.createElement("div");h.className="moo-calendar__presets",[["today","Today"],["tomorrow","Tomorrow"],["in-3-days","In 3 days"],["in-a-week","In a week"],["in-2-weeks","In 2 weeks"]].forEach(([l,u])=>{let o=t.createElement("button");o.className="btn btn-outline-secondary btn-sm moo-calendar__preset",o.type="button",o.dataset.calendarPreset=l,o.textContent=u,h.appendChild(o)}),i.appendChild(h)}this._element.classList.add("moo-calendar"),this._element.dataset.calendar=this._element.dataset.calendar||"",this._element.dataset.calendarMode=this._mode,this._element.dataset.calendarActiveDate=f(this._activeDate),this._mode==="single"&&this._selectedDate?this._element.dataset.calendarValue=f(this._selectedDate):delete this._element.dataset.calendarValue,this._mode==="range"?(this._element.dataset.calendarStartValue=this._rangeStart?f(this._rangeStart):"",this._element.dataset.calendarEndValue=this._rangeEnd?f(this._rangeEnd):""):(delete this._element.dataset.calendarStartValue,delete this._element.dataset.calendarEndValue),this._element.replaceChildren(i)}},H=class e{static getInstance(t){return t?.nodeType===1&&I.get(t)||null}static getOrCreateInstance(t,i={}){return e.getInstance(t)||new e(t,i)}constructor(t,i={}){if(!z(t,"[data-datepicker]"))throw new TypeError("MooDatepicker requires a [data-datepicker] root element.");let a=I.get(t);if(a)return a;if(this._element=t,this._document=t.ownerDocument,this._window=this._document.defaultView||window,this._listeners=[],this._floatingListeners=[],this._disposed=!1,this._positionPopover=null,this._popoverPortal=null,this._trigger=t.querySelector("[data-datepicker-trigger]"),this._popover=t.querySelector("[data-datepicker-popover]"),this._label=t.querySelector("[data-datepicker-label]"),this._input=t.querySelector("[data-datepicker-input]")||t.querySelector('input[type="hidden"]'),this._validationInput=t.querySelector("[data-datepicker-validation]"),this._calendarRoot=t.querySelector("[data-calendar]"),!this._trigger||!this._popover||!this._label||!this._input||!this._calendarRoot)throw new TypeError("MooDatepicker requires a trigger, popover, calendar, and hidden input.");this._config=U(t,{...i,value:i.value||this._input.value||t.dataset.datepickerValue}),this._placeholder=this._config.placeholder,this._defaultValue=this._input.defaultValue||this._input.getAttribute("value")||"",this.calendar=L.getOrCreateInstance(this._calendarRoot,{...this._config,mode:"single",value:this._input.value||this._config.value}),I.set(t,this),this._syncFromCalendar(),this._bindEvents()}dispose(){this._disposed||(this._disposed=!0,E(this._listeners),this.hide(!1),F(this),R(this),E(this._floatingListeners),this.calendar?.dispose(),I.get(this._element)===this&&I.delete(this._element))}show(){this._trigger.disabled||this._element.dataset.datepickerDisabled==="true"||this.isOpen()||g(this._element,this._window,"show.moo.datepicker",{},!0)&&(this._popover.hidden=!1,this._popover.classList.add("show"),ot(this),this._trigger.setAttribute("aria-expanded","true"),this.calendar.focusActiveDay(),g(this._element,this._window,"shown.moo.datepicker"))}hide(t=!0){this.isOpen()&&g(this._element,this._window,"hide.moo.datepicker",{},!0)&&(this._popover.hidden=!0,this._popover.classList.remove("show"),F(this),this._trigger.setAttribute("aria-expanded","false"),t&&this._trigger.focus({preventScroll:!0}),g(this._element,this._window,"hidden.moo.datepicker"))}toggle(){this.isOpen()?this.hide():this.show()}isOpen(){return!this._popover.hidden}getDate(t=void 0){return this.calendar.getDate(t)}setDate(t,i={}){let a=this.calendar.setDate(t,{emit:!1});return a&&(this._syncFromCalendar(),i.emit!==!1&&this._emitChange()),a}clear(t={}){this.calendar.clear({emit:!1}),this._syncFromCalendar(),t.emit!==!1&&this._emitChange()}_bindEvents(){c(this._listeners,this._trigger,"click",()=>this.toggle()),c(this._listeners,this._popover,"keydown",i=>{i.key==="Escape"&&(i.preventDefault(),this.hide())}),c(this._listeners,this._document,"pointerdown",i=>{this.isOpen()&&!O(this,i.target)&&this._window.setTimeout(()=>{this.isOpen()&&!O(this,i.target)&&this.hide()},0)}),c(this._listeners,this._calendarRoot,"change.moo.calendar",i=>{this._syncFromCalendar(),this._emitChange(),i.detail.complete&&this.hide()});let t=this._input.form||this._element.closest("form");c(this._listeners,this._validationInput,"invalid",i=>{i.preventDefault(),j(this._element,this._trigger,!0),this._trigger.focus({preventScroll:!0})}),c(this._listeners,t,"reset",()=>{this._window.setTimeout(()=>{this._defaultValue?this.setDate(this._defaultValue,{emit:!1}):this.clear({emit:!1})},0)})}_syncFromCalendar(){let t=this.calendar.getDate("yyyy-mm-dd")||"";K(this._input,t),rt(this._validationInput,t),st(this._element,this._trigger,this._validationInput),this._element.dataset.datepickerValue=t,this._label.dataset.datepickerEmpty=t?"false":"true",this._label.textContent=t?x(d(t),this._config.locale):this._placeholder}_emitChange(){g(this._element,this._window,"change.moo.datepicker",{date:this.getDate(),value:this.getDate("yyyy-mm-dd")||""})}},nt=class e{static getInstance(t){return t?.nodeType===1&&M.get(t)||null}static getOrCreateInstance(t,i={}){return e.getInstance(t)||new e(t,i)}constructor(t,i={}){if(!z(t,"[data-datepicker-range]"))throw new TypeError("MooDateRangePicker requires a [data-datepicker-range] root element.");let a=M.get(t);if(a)return a;if(this._element=t,this._document=t.ownerDocument,this._window=this._document.defaultView||window,this._listeners=[],this._floatingListeners=[],this._disposed=!1,this._positionPopover=null,this._popoverPortal=null,this._trigger=t.querySelector("[data-datepicker-trigger]"),this._popover=t.querySelector("[data-datepicker-popover]"),this._label=t.querySelector("[data-datepicker-label]"),this._startInput=t.querySelector("[data-datepicker-range-start]"),this._endInput=t.querySelector("[data-datepicker-range-end]"),this._validationInput=t.querySelector("[data-datepicker-validation]"),this._calendarRoot=t.querySelector("[data-calendar]"),!this._trigger||!this._popover||!this._label||!this._startInput||!this._endInput||!this._calendarRoot)throw new TypeError("MooDateRangePicker requires a trigger, popover, calendar, and start/end hidden inputs.");this._config=U(t,{...i,mode:"range",startValue:i.startValue||this._startInput.value||t.dataset.datepickerStartValue,endValue:i.endValue||this._endInput.value||t.dataset.datepickerEndValue}),this._placeholder=this._config.placeholder,this._defaultStartValue=this._startInput.defaultValue||this._startInput.getAttribute("value")||"",this._defaultEndValue=this._endInput.defaultValue||this._endInput.getAttribute("value")||"",this.calendar=L.getOrCreateInstance(this._calendarRoot,this._config),M.set(t,this),this._syncFromCalendar(),this._bindEvents()}dispose(){this._disposed||(this._disposed=!0,E(this._listeners),this.hide(!1),F(this),R(this),E(this._floatingListeners),this.calendar?.dispose(),M.get(this._element)===this&&M.delete(this._element))}show(){this._trigger.disabled||this._element.dataset.datepickerDisabled==="true"||this.isOpen()||g(this._element,this._window,"show.moo.datepicker",{},!0)&&(this._popover.hidden=!1,this._popover.classList.add("show"),ot(this),this._trigger.setAttribute("aria-expanded","true"),this.calendar.focusActiveDay(),g(this._element,this._window,"shown.moo.datepicker"))}hide(t=!0){this.isOpen()&&g(this._element,this._window,"hide.moo.datepicker",{},!0)&&(this._popover.hidden=!0,this._popover.classList.remove("show"),F(this),this._trigger.setAttribute("aria-expanded","false"),t&&this._trigger.focus({preventScroll:!0}),g(this._element,this._window,"hidden.moo.datepicker"))}toggle(){this.isOpen()?this.hide():this.show()}isOpen(){return!this._popover.hidden}getDates(t=void 0){return this.calendar.getDates(t)}setDates(t,i,a={}){let n=this.calendar.setDates(t,i,{emit:!1});return n&&(this._syncFromCalendar(),a.emit!==!1&&this._emitChange()),n}clear(t={}){this.calendar.clear({emit:!1}),this._syncFromCalendar(),t.emit!==!1&&this._emitChange()}_bindEvents(){c(this._listeners,this._trigger,"click",()=>this.toggle()),c(this._listeners,this._popover,"keydown",a=>{a.key==="Escape"&&(a.preventDefault(),this.hide())}),c(this._listeners,this._document,"pointerdown",a=>{this.isOpen()&&!O(this,a.target)&&this._window.setTimeout(()=>{this.isOpen()&&!O(this,a.target)&&this.hide()},0)});let t=()=>{this._window.setTimeout(()=>{this.isOpen()&&!O(this,this._document.activeElement)&&this.hide(!1)},0)};c(this._listeners,this._element,"focusout",t),c(this._listeners,this._popover,"focusout",t),c(this._listeners,this._calendarRoot,"change.moo.calendar",a=>{this._syncFromCalendar(),this._emitChange(),a.detail.complete?this.hide():this.calendar.focusActiveDay()});let i=this._startInput.form||this._element.closest("form");c(this._listeners,this._validationInput,"invalid",a=>{a.preventDefault(),j(this._element,this._trigger,!0),this._trigger.focus({preventScroll:!0})}),c(this._listeners,i,"reset",()=>{this._window.setTimeout(()=>{this.setDates(this._defaultStartValue,this._defaultEndValue,{emit:!1})},0)})}_syncFromCalendar(){let[t="",i=""]=this.calendar.getDates("yyyy-mm-dd");K(this._startInput,t||""),K(this._endInput,i||""),rt(this._validationInput,t&&i?"".concat(t," - ").concat(i):""),st(this._element,this._trigger,this._validationInput),this._element.dataset.datepickerStartValue=t||"",this._element.dataset.datepickerEndValue=i||"",this._label.dataset.datepickerEmpty=t?"false":"true",t&&i?this._label.textContent="".concat(x(d(t),this._config.locale)," - ").concat(x(d(i),this._config.locale)):t?this._label.textContent=x(d(t),this._config.locale):this._label.textContent=this._placeholder}_emitChange(){let[t,i]=this.getDates(),[a="",n=""]=this.getDates("yyyy-mm-dd");g(this._element,this._window,"change.moo.datepicker",{startDate:t,endDate:i,startValue:a,endValue:n})}};export{L as MooCalendar,nt as MooDateRangePicker,H as default};
7
+ var Q='.moo-ui[data-bs-theme="light"], .moo-ui[data-bs-theme="dark"]',ce="[data-moo-overlay-host]";function he(t){return t?.nodeType===9?t:t?.ownerDocument?t.ownerDocument:typeof document>"u"?null:document}function ue(t){return!!t?.matches?.(Q)}function _e(t){let e=he(t);return t?.nodeType===9||t===e?.body?e?.body?.firstElementChild||null:t}function q(t=typeof document>"u"?null:document){let e=_e(t);return e?ue(e)?e:e.closest?.(Q)||null:null}function X(t){return t?Array.from(t.children||[]).find(e=>e.matches?.(ce))||t:null}var M=new WeakMap,O=new WeakMap,P=new WeakMap,w="en",Se=1440*60*1e3,fe=new Date(2026,7,16),A=8;function z(t,e){return t?.nodeType===1&&!!t.matches?.(e)}function c(t,e,i,a,n){e&&(e.addEventListener(i,a,n),t.push({target:e,type:i,handler:a,options:n}))}function C(t){t.forEach(({target:e,type:i,handler:a,options:n})=>{e.removeEventListener(i,a,n)}),t.length=0}function d(t){if(!t)return null;if(t instanceof Date)return Number.isNaN(t.getTime())?null:new Date(t.getFullYear(),t.getMonth(),t.getDate());if(typeof t=="number")return d(new Date(t));let e=String(t).trim(),i=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(i){let a=new Date(Number(i[1]),Number(i[2])-1,Number(i[3]));return a.getFullYear()===Number(i[1])&&a.getMonth()===Number(i[2])-1&&a.getDate()===Number(i[3])?a:null}return null}function Z(t){return String(t).padStart(2,"0")}function f(t){return"".concat(t.getFullYear(),"-").concat(Z(t.getMonth()+1),"-").concat(Z(t.getDate()))}function g(t,e){return!t||!e?0:t.getTime()-e.getTime()}function S(t,e){return!!(t&&e&&f(t)===f(e))}function v(t,e){return new Date(t.getFullYear(),t.getMonth(),t.getDate()+e)}function ee(t,e){let i=new Date(t.getFullYear(),t.getMonth()+e,1),a=Math.min(t.getDate(),$(i.getFullYear(),i.getMonth()));return new Date(i.getFullYear(),i.getMonth(),a)}function N(t=w){try{if(typeof Intl<"u"&&typeof Intl.Locale=="function"){let e=new Intl.Locale(t||w),i=e.weekInfo||e.getWeekInfo?.();if(Number.isInteger(i?.firstDay))return i.firstDay%7}}catch{}return 0}function me(t=w){let e=N(t);return Array.from({length:7},(i,a)=>v(fe,(e+a)%7))}function b(t){return new Date(t.getFullYear(),t.getMonth(),1)}function $(t,e){return new Date(t,e+1,0).getDate()}function te(t,e,i){return e&&g(t,e)<0?new Date(e):i&&g(t,i)>0?new Date(i):t}function pe(t){if(Array.isArray(t))return t.map(d).filter(Boolean).map(f);if(!t)return[];let e=String(t).trim();if(!e)return[];try{let i=JSON.parse(e);if(Array.isArray(i))return i.map(d).filter(Boolean).map(f)}catch{}return e.split(",").map(d).filter(Boolean).map(f)}function I(t,e=w){return t?new Intl.DateTimeFormat(e||w,{month:"short",day:"numeric",year:"numeric"}).format(t):""}function ie(t,e=w){return new Intl.DateTimeFormat(e||w,{month:"long",year:"numeric"}).format(t)}function B(t,e,i=w){if(t)return e==="yyyy-mm-dd"?f(t):e?I(t,i):new Date(t)}function U(t,e={}){let i=t.dataset||{},a=e.locale||i.datepickerLocale||i.calendarLocale||w,n=d(e.minDate||i.calendarMinDate||i.datepickerMinDate),r=d(e.maxDate||i.calendarMaxDate||i.datepickerMaxDate);return{locale:a,mode:e.mode||i.calendarMode||i.datepickerMode||"single",placeholder:e.placeholder||i.datepickerPlaceholder||"Pick a date",value:e.value||i.calendarValue||i.datepickerValue||"",startValue:e.startValue||i.calendarStartValue||i.datepickerStartValue||"",endValue:e.endValue||i.calendarEndValue||i.datepickerEndValue||"",minDate:n,maxDate:r,disabledDates:pe(e.disabledDates||i.calendarDisabledDates||i.datepickerDisabledDates),captionLayout:e.captionLayout||i.calendarCaptionLayout||"",showPresets:e.showPresets??(i.calendarShowPresets==="true"||i.datepickerShowPresets==="true")}}function y(t,e,i,a={},n=!1){return t.dispatchEvent(new e.CustomEvent(i,{bubbles:!0,cancelable:n,detail:a}))}function W(t){return t?("datepickerFormDefault"in t.dataset||(t.dataset.datepickerFormDefault=t.getAttribute("value")||""),t.dataset.datepickerFormDefault):""}function K(t,e){t&&(t.value=e||"")}function oe(t,e){t&&(t.value=e||"")}function j(t,e,i){if(i){t.dataset.invalid="true",e.classList.add("is-invalid"),e.setAttribute("aria-invalid","true");return}delete t.dataset.invalid,e.classList.remove("is-invalid"),e.removeAttribute("aria-invalid")}function le(t,e,i){i?.required&&i.checkValidity()&&j(t,e,!1)}function ae(t,e,i){return i<e?e:Math.min(Math.max(t,e),i)}function ge(t,e,i){let a=t?.ownerDocument?.defaultView||window,n=t?a.getComputedStyle(t).getPropertyValue(e).trim():"",r=Number.parseFloat(n);if(!Number.isFinite(r))return i;if(n.endsWith("rem")){let s=t.ownerDocument.documentElement,m=Number.parseFloat(a.getComputedStyle(s).fontSize);return Number.isFinite(m)?r*m:i}if(n.endsWith("em")){let s=Number.parseFloat(a.getComputedStyle(t).fontSize);return Number.isFinite(s)?r*s:i}return Number.isFinite(r)?r:i}function F(t,e){return!!(e&&(t._element.contains(e)||t._popover.contains(e)))}function ne(t){let i=q(t._trigger)?.getAttribute("data-bs-theme")||null,a=t._document.defaultView?.getComputedStyle(t._trigger).direction;i?t._popover.setAttribute("data-bs-theme",i):t._popover.removeAttribute("data-bs-theme"),a==="ltr"||a==="rtl"?t._popover.setAttribute("dir",a):t._popover.removeAttribute("dir")}function De(t){let e=t._popover,i=q(t._trigger),a=X(i)||t._document.body||t._document.documentElement;if(a){if(t._popoverPortal?.portal===a&&e.parentElement===a){ne(t);return}Y(t),t._popoverPortal={parent:e.parentNode,nextSibling:e.nextSibling,owner:i,portal:a,hadTheme:e.hasAttribute("data-bs-theme"),theme:e.getAttribute("data-bs-theme"),hadDirection:e.hasAttribute("dir"),direction:e.getAttribute("dir")},a.appendChild(e),ne(t)}}function Y(t){let e=t._popoverPortal;if(!e)return;let i=t._popover;e.owner?.isConnected===!1?i.remove():e.parent?.isConnected?e.nextSibling?.parentNode===e.parent?e.parent.insertBefore(i,e.nextSibling):e.parent.appendChild(i):i.remove(),e.hadTheme?i.setAttribute("data-bs-theme",e.theme):i.removeAttribute("data-bs-theme"),e.hadDirection?i.setAttribute("dir",e.direction):i.removeAttribute("dir"),t._popoverPortal=null}function ye(t,e,i,a){let n=ge(i,"--moo-datepicker-popover-offset",6),r=getComputedStyle(t).direction;e.style.position="fixed",e.style.inset="auto",e.style.right="auto",e.style.bottom="auto",e.style.maxHeight="",e.style.overflowY="";let s=t.getBoundingClientRect(),m=e.getBoundingClientRect(),D=a.innerWidth,u=a.innerHeight,k=r==="rtl"?s.right-m.width:s.left,x=ae(k,A,D-m.width-A),V=s.bottom+n<=u?u-s.bottom-n-A:0,h=s.top-n-A,l=m.height>V&&h>V,_=l?"top":"bottom",o=Math.max(0,l?h:V),T=Math.min(m.height,o),E=l?s.top-n-T:s.bottom+n;e.style.left="".concat(Math.round(x),"px"),e.style.top="".concat(Math.round(ae(E,A,u-T-A)),"px"),o>0&&(e.style.maxHeight="".concat(Math.floor(o),"px"),e.style.overflowY="auto"),e.dataset.datepickerPlacement=_}function we(t){t.style.position="",t.style.inset="",t.style.right="",t.style.bottom="",t.style.left="",t.style.top="",t.style.maxHeight="",t.style.overflowY="",delete t.dataset.datepickerPlacement}function de(t){C(t._floatingListeners),De(t);let e=()=>{t.isOpen()&&ye(t._trigger,t._popover,t._element,t._window)};t._positionPopover=e,e(),c(t._floatingListeners,t._window,"resize",e),c(t._floatingListeners,t._window,"scroll",e,!0),c(t._floatingListeners,t._document,"scroll",e,!0)}function L(t){C(t._floatingListeners),t._positionPopover=null,we(t._popover),Y(t)}function be(t,e){return new Intl.DateTimeFormat(e||w,{month:"short"}).format(new Date(2026,t,1))}function ve(t,e,i){let a=t?t.getFullYear():i.getFullYear()-100,n=e?e.getFullYear():i.getFullYear()+20,r=[];for(let s=a;s<=n;s+=1)r.push(s);return r}function re(t,e,i=""){let a=t.createElement("span");return a.className=i,a.setAttribute("aria-hidden","true"),a.textContent=e,a}var R=class t{static getInstance(e){return e?.nodeType===1&&O.get(e)||null}static getOrCreateInstance(e,i={}){return t.getInstance(e)||new t(e,i)}constructor(e,i={}){if(!z(e,"[data-calendar]"))throw new TypeError("MooCalendar requires a [data-calendar] root element.");let a=O.get(e);if(a)return a;this._element=e,this._document=e.ownerDocument,this._window=this._document.defaultView||window,this._listeners=[],this._disposed=!1,this._config=U(e,i),this._mode=this._config.mode==="range"?"range":"single",this._disabledDates=new Set(this._config.disabledDates),this._selectedDate=d(this._config.value),this._rangeStart=d(this._config.startValue),this._rangeEnd=d(this._config.endValue),this._activeDate=this._nearestEnabledDate(this._rangeStart||this._selectedDate||new Date),this._viewDate=b(this._activeDate),this._captionId=this._element.id?"".concat(this._element.id,"-caption"):"moo-calendar-caption-".concat(Math.random().toString(36).slice(2)),this._labelId=this._element.id?"".concat(this._element.id,"-label"):"moo-calendar-label-".concat(Math.random().toString(36).slice(2)),O.set(e,this),this._bindEvents(),this._render()}dispose(){this._disposed||(this._disposed=!0,C(this._listeners),this._element.replaceChildren(),O.get(this._element)===this&&O.delete(this._element))}getDate(e=void 0){return this._mode==="range"?this.getDates(e):B(this._selectedDate,e,this._config.locale)}getDates(e=void 0){return[B(this._rangeStart,e,this._config.locale),B(this._rangeEnd,e,this._config.locale)]}setDate(e,i={}){if(this._mode!=="single")return!1;let a=d(e);return!a||this._isDisabled(a)?!1:(this._selectedDate=a,this._activeDate=a,this._viewDate=b(a),this._render(),i.emit!==!1&&this._emitChange(!0),!0)}setDates(e,i,a={}){if(this._mode!=="range")return!1;let n=d(e),r=d(i);return n&&this._isDisabled(n)||r&&this._isDisabled(r)?!1:(this._rangeStart=n,this._rangeEnd=r,this._rangeStart&&this._rangeEnd&&g(this._rangeStart,this._rangeEnd)>0&&([this._rangeStart,this._rangeEnd]=[this._rangeEnd,this._rangeStart]),this._activeDate=this._rangeEnd||this._rangeStart||this._activeDate,this._viewDate=b(this._activeDate),this._render(),a.emit!==!1&&this._emitChange(!!(this._rangeStart&&this._rangeEnd)),!0)}clear(e={}){this._selectedDate=null,this._rangeStart=null,this._rangeEnd=null,this._render(),e.emit!==!1&&this._emitChange(!1)}focusActiveDay(){this._dayButton(this._activeDate)?.focus()}_bindEvents(){c(this._listeners,this._element,"click",e=>{let i=e.target,a=i.closest?.("[data-calendar-day]"),n=i.closest?.("[data-calendar-prev]"),r=i.closest?.("[data-calendar-next]"),s=i.closest?.("[data-calendar-preset]");n?this._changeMonth(-1,!0):r?this._changeMonth(1,!0):s?this._selectPreset(s.dataset.calendarPreset):a&&this._selectDate(d(a.dataset.calendarDay),!0)}),c(this._listeners,this._element,"keydown",e=>{e.target.closest?.("[data-calendar-day]")&&this._handleDayKeydown(e)}),c(this._listeners,this._element,"change",e=>{e.target.matches?.("[data-calendar-month]")&&this._setActiveMonth(this._viewDate.getFullYear(),Number(e.target.value),!0),e.target.matches?.("[data-calendar-year]")&&this._setActiveMonth(Number(e.target.value),this._viewDate.getMonth(),!0)})}_emitChange(e){y(this._element,this._window,"change.moo.calendar",{date:this._selectedDate?new Date(this._selectedDate):void 0,value:this._selectedDate?f(this._selectedDate):"",startDate:this._rangeStart?new Date(this._rangeStart):void 0,endDate:this._rangeEnd?new Date(this._rangeEnd):void 0,startValue:this._rangeStart?f(this._rangeStart):"",endValue:this._rangeEnd?f(this._rangeEnd):"",complete:e})}_changeMonth(e,i){let a=b(ee(this._viewDate,e));this._setActiveMonth(a.getFullYear(),a.getMonth(),i)}_setActiveMonth(e,i,a=!1){let n=Math.min(this._activeDate.getDate(),$(e,i));this._activeDate=this._nearestEnabledDate(new Date(e,i,n)),this._viewDate=b(this._activeDate),this._render(),a&&this.focusActiveDay()}_selectPreset(e){if(!e)return;let i=new Date,a={today:0,tomorrow:1,"in-3-days":3,"in-a-week":7,"in-2-weeks":14};e in a&&this._selectDate(v(i,a[e]),!0)}_handleDayKeydown(e){let i=e.target.closest?.("[data-calendar-day]"),a=d(i?.dataset?.calendarDay);a&&g(a,this._activeDate)!==0&&(this._activeDate=a);let n={ArrowRight:1,ArrowLeft:-1,ArrowDown:7,ArrowUp:-7},r=null,s=!1;if(e.key in n)r=v(this._activeDate,n[e.key]);else if(e.key==="Home"){let D=N(this._config.locale),u=(this._activeDate.getDay()-D+7)%7;r=v(this._activeDate,-u)}else if(e.key==="End"){let D=N(this._config.locale),u=(this._activeDate.getDay()-D+7)%7;r=v(this._activeDate,6-u)}else if(e.key==="PageUp"||e.key==="PageDown"){let D=ee(this._activeDate,e.key==="PageUp"?-1:1),{minDate:u,maxDate:k}=this._config;r=te(D,u,k),s=[u,k].some(x=>x&&g(r,x)===0)}else if(e.key==="Enter"||e.key===" "||e.key==="Spacebar"){e.preventDefault(),this._selectDate(this._activeDate,!0);return}else return;e.preventDefault();let m=g(r,this._activeDate)<0;this._setActiveDate(r,!0,m!==s?-1:1)}_setActiveDate(e,i=!1,a=0){let n=a===0?this._nearestEnabledDate(e):this._nextEnabledDate(e,a);this._activeDate=n,this._viewDate=b(n),this._render(),i&&this.focusActiveDay()}_nextEnabledDate(e,i){let a=d(e);if(!a)return this._activeDate;let n=i<0?-1:1;for(let r=0;r<366&&!(this._config.minDate&&g(a,this._config.minDate)<0||this._config.maxDate&&g(a,this._config.maxDate)>0);r+=1){if(!this._isDisabled(a))return a;a=v(a,n)}return this._activeDate}_nearestEnabledDate(e){let i=te(d(e)||new Date,this._config.minDate,this._config.maxDate);if(!this._isDisabled(i))return i;let a=b(i),n=$(a.getFullYear(),a.getMonth());for(let r=1;r<=n;r+=1){let s=new Date(a.getFullYear(),a.getMonth(),r);if(!this._isDisabled(s))return s}return i}_selectDate(e,i){if(!(!e||this._isDisabled(e))){if(this._activeDate=e,this._viewDate=b(e),this._mode==="range"){!this._rangeStart||this._rangeEnd||g(e,this._rangeStart)<0?(this._rangeStart=e,this._rangeEnd=null):this._rangeEnd=e,this._render(),i&&this._emitChange(!!(this._rangeStart&&this._rangeEnd));return}this._selectedDate=e,this._render(),i&&this._emitChange(!0)}}_isDisabled(e){return!e||this._config.minDate&&g(e,this._config.minDate)<0||this._config.maxDate&&g(e,this._config.maxDate)>0?!0:this._disabledDates.has(f(e))}_isSelected(e){return this._mode==="range"?S(e,this._rangeStart)||S(e,this._rangeEnd):S(e,this._selectedDate)}_rangeState(e){return this._mode!=="range"||!this._rangeStart?"":S(e,this._rangeStart)?"start":S(e,this._rangeEnd)?"end":this._rangeStart&&this._rangeEnd&&g(e,this._rangeStart)>0&&g(e,this._rangeEnd)<0?"middle":""}_dayButton(e){return this._element.querySelector('[data-calendar-day="'.concat(f(e),'"]'))}_render(){let e=this._document,i=e.createDocumentFragment(),a=e.createElement("div");a.className="moo-calendar__header";let n=e.createElement("button");n.className="btn btn-ghost btn-icon-sm moo-calendar__nav",n.type="button",n.dataset.calendarPrev="true",n.setAttribute("aria-label","Previous month"),n.appendChild(re(e,"\u2039","moo-calendar__nav-icon"));let r=e.createElement("button");r.className="btn btn-ghost btn-icon-sm moo-calendar__nav",r.type="button",r.dataset.calendarNext="true",r.setAttribute("aria-label","Next month"),r.appendChild(re(e,"\u203A","moo-calendar__nav-icon"));let s=e.createElement("div");if(s.className="moo-calendar__caption",s.id=this._captionId,s.setAttribute("aria-live","polite"),this._config.captionLayout==="dropdown"){let h=e.createElement("select");h.className="moo-calendar__select",h.dataset.calendarMonth="true",h.setAttribute("aria-label","Month");for(let _=0;_<12;_+=1){let o=e.createElement("option");o.value=String(_),o.textContent=be(_,this._config.locale),o.selected=_===this._viewDate.getMonth(),h.appendChild(o)}let l=e.createElement("select");l.className="moo-calendar__select",l.dataset.calendarYear="true",l.setAttribute("aria-label","Year"),ve(this._config.minDate,this._config.maxDate,this._viewDate).forEach(_=>{let o=e.createElement("option");o.value=String(_),o.textContent=String(_),o.selected=_===this._viewDate.getFullYear(),l.appendChild(o)}),s.append(h,l)}else s.textContent=ie(this._viewDate,this._config.locale);a.append(n,s,r),i.appendChild(a);let m=e.createElement("div");m.id=this._labelId,m.className="visually-hidden",m.textContent=this._element.getAttribute("aria-label")||ie(this._viewDate,this._config.locale),i.appendChild(m);let D=e.createElement("div");D.className="moo-calendar__weekdays",D.setAttribute("role","row"),me(this._config.locale).forEach(h=>{let l=e.createElement("span");l.className="moo-calendar__weekday",l.setAttribute("role","columnheader"),l.textContent=new Intl.DateTimeFormat(this._config.locale,{weekday:"narrow"}).format(h),D.appendChild(l)});let u=e.createElement("div");u.className="moo-calendar__grid",u.setAttribute("role","grid"),u.setAttribute("aria-labelledby",this._labelId),u.appendChild(D);let k=b(this._viewDate),x=N(this._config.locale),V=v(k,-((k.getDay()-x+7)%7));for(let h=0;h<6;h+=1){let l=e.createElement("div");l.className="moo-calendar__week",l.setAttribute("role","row");for(let _=0;_<7;_+=1){let o=v(V,h*7+_),T=f(o),E=e.createElement("div");E.className="moo-calendar__cell",E.setAttribute("role","gridcell");let p=e.createElement("button");p.className="moo-calendar__day",p.type="button",p.dataset.calendarDay=T,p.textContent=String(o.getDate()),p.tabIndex=S(o,this._activeDate)?0:-1,p.setAttribute("aria-label",I(o,this._config.locale));let G=this._isSelected(o);p.dataset.calendarSelected=String(G),E.setAttribute("aria-selected",G?"true":"false"),o.getMonth()!==this._viewDate.getMonth()&&(p.dataset.calendarOutside="true"),S(o,new Date)&&(p.dataset.calendarToday="true",p.setAttribute("aria-current","date"));let J=this._rangeState(o);J&&(p.dataset.calendarRange=J),this._isDisabled(o)&&(p.disabled=!0,p.setAttribute("aria-disabled","true")),E.appendChild(p),l.appendChild(E)}u.appendChild(l)}if(i.appendChild(u),this._config.showPresets){let h=e.createElement("div");h.className="moo-calendar__presets",[["today","Today"],["tomorrow","Tomorrow"],["in-3-days","In 3 days"],["in-a-week","In a week"],["in-2-weeks","In 2 weeks"]].forEach(([l,_])=>{let o=e.createElement("button");o.className="btn btn-outline-secondary btn-sm moo-calendar__preset",o.type="button",o.dataset.calendarPreset=l,o.textContent=_,h.appendChild(o)}),i.appendChild(h)}this._element.classList.add("moo-calendar"),this._element.dataset.calendar=this._element.dataset.calendar||"",this._element.dataset.calendarMode=this._mode,this._element.dataset.calendarActiveDate=f(this._activeDate),this._mode==="single"&&this._selectedDate?this._element.dataset.calendarValue=f(this._selectedDate):delete this._element.dataset.calendarValue,this._mode==="range"?(this._element.dataset.calendarStartValue=this._rangeStart?f(this._rangeStart):"",this._element.dataset.calendarEndValue=this._rangeEnd?f(this._rangeEnd):""):(delete this._element.dataset.calendarStartValue,delete this._element.dataset.calendarEndValue),this._element.replaceChildren(i)}},H=class t{static getInstance(e){return e?.nodeType===1&&M.get(e)||null}static getOrCreateInstance(e,i={}){return t.getInstance(e)||new t(e,i)}constructor(e,i={}){if(!z(e,"[data-datepicker]"))throw new TypeError("MooDatepicker requires a [data-datepicker] root element.");let a=M.get(e);if(a)return a;if(this._element=e,this._document=e.ownerDocument,this._window=this._document.defaultView||window,this._listeners=[],this._floatingListeners=[],this._disposed=!1,this._positionPopover=null,this._popoverPortal=null,this._trigger=e.querySelector("[data-datepicker-trigger]"),this._popover=e.querySelector("[data-datepicker-popover]"),this._label=e.querySelector("[data-datepicker-label]"),this._input=e.querySelector("[data-datepicker-input]")||e.querySelector('input[type="hidden"]'),this._validationInput=e.querySelector("[data-datepicker-validation]"),this._calendarRoot=e.querySelector("[data-calendar]"),!this._trigger||!this._popover||!this._label||!this._input||!this._calendarRoot)throw new TypeError("MooDatepicker requires a trigger, popover, calendar, and hidden input.");this._config=U(e,{...i,value:i.value||this._input.value||e.dataset.datepickerValue}),this._placeholder=this._config.placeholder,this._defaultValue=W(this._input),this.calendar=R.getOrCreateInstance(this._calendarRoot,{...this._config,mode:"single",value:this._input.value||this._config.value}),M.set(e,this),this._syncFromCalendar(),this._bindEvents()}dispose(){this._disposed||(this._disposed=!0,C(this._listeners),this.hide(!1),L(this),Y(this),C(this._floatingListeners),this.calendar?.dispose(),M.get(this._element)===this&&M.delete(this._element))}show(){this._trigger.disabled||this._element.dataset.datepickerDisabled==="true"||this.isOpen()||y(this._element,this._window,"show.moo.datepicker",{},!0)&&(this._popover.hidden=!1,this._popover.classList.add("show"),de(this),this._trigger.setAttribute("aria-expanded","true"),this.calendar.focusActiveDay(),y(this._element,this._window,"shown.moo.datepicker"))}hide(e=!0){this.isOpen()&&y(this._element,this._window,"hide.moo.datepicker",{},!0)&&(this._popover.hidden=!0,this._popover.classList.remove("show"),L(this),this._trigger.setAttribute("aria-expanded","false"),e&&this._trigger.focus({preventScroll:!0}),y(this._element,this._window,"hidden.moo.datepicker"))}toggle(){this.isOpen()?this.hide():this.show()}isOpen(){return!this._popover.hidden}getDate(e=void 0){return this.calendar.getDate(e)}setDate(e,i={}){let a=this.calendar.setDate(e,{emit:!1});return a&&(this._syncFromCalendar(),i.emit!==!1&&this._emitChange()),a}clear(e={}){this.calendar.clear({emit:!1}),this._syncFromCalendar(),e.emit!==!1&&this._emitChange()}_bindEvents(){c(this._listeners,this._trigger,"click",()=>this.toggle()),c(this._listeners,this._popover,"keydown",i=>{i.key==="Escape"&&(i.preventDefault(),this.hide())}),c(this._listeners,this._document,"pointerdown",i=>{this.isOpen()&&!F(this,i.target)&&this._window.setTimeout(()=>{this.isOpen()&&!F(this,i.target)&&this.hide()},0)}),c(this._listeners,this._calendarRoot,"change.moo.calendar",i=>{this._syncFromCalendar(),this._emitChange(),i.detail.complete&&this.hide()});let e=this._input.form||this._element.closest("form");c(this._listeners,this._validationInput,"invalid",i=>{i.preventDefault(),j(this._element,this._trigger,!0),this._trigger.focus({preventScroll:!0})}),c(this._listeners,e,"reset",()=>{this._window.setTimeout(()=>{this._defaultValue?this.setDate(this._defaultValue,{emit:!1}):this.clear({emit:!1})},0)})}_syncFromCalendar(){let e=this.calendar.getDate("yyyy-mm-dd")||"";K(this._input,e),oe(this._validationInput,e),le(this._element,this._trigger,this._validationInput),this._element.dataset.datepickerValue=e,this._label.dataset.datepickerEmpty=e?"false":"true",this._label.textContent=e?I(d(e),this._config.locale):this._placeholder}_emitChange(){y(this._element,this._window,"change.moo.datepicker",{date:this.getDate(),value:this.getDate("yyyy-mm-dd")||""})}},se=class t{static getInstance(e){return e?.nodeType===1&&P.get(e)||null}static getOrCreateInstance(e,i={}){return t.getInstance(e)||new t(e,i)}constructor(e,i={}){if(!z(e,"[data-datepicker-range]"))throw new TypeError("MooDateRangePicker requires a [data-datepicker-range] root element.");let a=P.get(e);if(a)return a;if(this._element=e,this._document=e.ownerDocument,this._window=this._document.defaultView||window,this._listeners=[],this._floatingListeners=[],this._disposed=!1,this._positionPopover=null,this._popoverPortal=null,this._trigger=e.querySelector("[data-datepicker-trigger]"),this._popover=e.querySelector("[data-datepicker-popover]"),this._label=e.querySelector("[data-datepicker-label]"),this._startInput=e.querySelector("[data-datepicker-range-start]"),this._endInput=e.querySelector("[data-datepicker-range-end]"),this._validationInput=e.querySelector("[data-datepicker-validation]"),this._calendarRoot=e.querySelector("[data-calendar]"),!this._trigger||!this._popover||!this._label||!this._startInput||!this._endInput||!this._calendarRoot)throw new TypeError("MooDateRangePicker requires a trigger, popover, calendar, and start/end hidden inputs.");this._config=U(e,{...i,mode:"range",startValue:i.startValue||this._startInput.value||e.dataset.datepickerStartValue,endValue:i.endValue||this._endInput.value||e.dataset.datepickerEndValue}),this._placeholder=this._config.placeholder,this._defaultStartValue=W(this._startInput),this._defaultEndValue=W(this._endInput),this.calendar=R.getOrCreateInstance(this._calendarRoot,this._config),P.set(e,this),this._syncFromCalendar(),this._bindEvents()}dispose(){this._disposed||(this._disposed=!0,C(this._listeners),this.hide(!1),L(this),Y(this),C(this._floatingListeners),this.calendar?.dispose(),P.get(this._element)===this&&P.delete(this._element))}show(){this._trigger.disabled||this._element.dataset.datepickerDisabled==="true"||this.isOpen()||y(this._element,this._window,"show.moo.datepicker",{},!0)&&(this._popover.hidden=!1,this._popover.classList.add("show"),de(this),this._trigger.setAttribute("aria-expanded","true"),this.calendar.focusActiveDay(),y(this._element,this._window,"shown.moo.datepicker"))}hide(e=!0){this.isOpen()&&y(this._element,this._window,"hide.moo.datepicker",{},!0)&&(this._popover.hidden=!0,this._popover.classList.remove("show"),L(this),this._trigger.setAttribute("aria-expanded","false"),e&&this._trigger.focus({preventScroll:!0}),y(this._element,this._window,"hidden.moo.datepicker"))}toggle(){this.isOpen()?this.hide():this.show()}isOpen(){return!this._popover.hidden}getDates(e=void 0){return this.calendar.getDates(e)}setDates(e,i,a={}){let n=this.calendar.setDates(e,i,{emit:!1});return n&&(this._syncFromCalendar(),a.emit!==!1&&this._emitChange()),n}clear(e={}){this.calendar.clear({emit:!1}),this._syncFromCalendar(),e.emit!==!1&&this._emitChange()}_bindEvents(){c(this._listeners,this._trigger,"click",()=>this.toggle()),c(this._listeners,this._popover,"keydown",a=>{a.key==="Escape"&&(a.preventDefault(),this.hide())}),c(this._listeners,this._document,"pointerdown",a=>{this.isOpen()&&!F(this,a.target)&&this._window.setTimeout(()=>{this.isOpen()&&!F(this,a.target)&&this.hide()},0)});let e=()=>{this._window.setTimeout(()=>{this.isOpen()&&!F(this,this._document.activeElement)&&this.hide(!1)},0)};c(this._listeners,this._element,"focusout",e),c(this._listeners,this._popover,"focusout",e),c(this._listeners,this._calendarRoot,"change.moo.calendar",a=>{this._syncFromCalendar(),this._emitChange(),a.detail.complete?this.hide():this.calendar.focusActiveDay()});let i=this._startInput.form||this._element.closest("form");c(this._listeners,this._validationInput,"invalid",a=>{a.preventDefault(),j(this._element,this._trigger,!0),this._trigger.focus({preventScroll:!0})}),c(this._listeners,i,"reset",()=>{this._window.setTimeout(()=>{this.setDates(this._defaultStartValue,this._defaultEndValue,{emit:!1})},0)})}_syncFromCalendar(){let[e="",i=""]=this.calendar.getDates("yyyy-mm-dd");K(this._startInput,e||""),K(this._endInput,i||""),oe(this._validationInput,e&&i?"".concat(e," - ").concat(i):""),le(this._element,this._trigger,this._validationInput),this._element.dataset.datepickerStartValue=e||"",this._element.dataset.datepickerEndValue=i||"",this._label.dataset.datepickerEmpty=e?"false":"true",e&&i?this._label.textContent="".concat(I(d(e),this._config.locale)," - ").concat(I(d(i),this._config.locale)):e?this._label.textContent=I(d(e),this._config.locale):this._label.textContent=this._placeholder}_emitChange(){let[e,i]=this.getDates(),[a="",n=""]=this.getDates("yyyy-mm-dd");y(this._element,this._window,"change.moo.datepicker",{startDate:e,endDate:i,startValue:a,endValue:n})}};export{R as MooCalendar,se as MooDateRangePicker,H as default};
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Moo UI floating-panel.js v2.1.0 (https://wpmoo.org/)
2
+ * Moo UI floating-panel.js v2.1.1 (https://wpmoo.org/)
3
3
  * Copyright 2026 WPMoo Authors
4
4
  * Licensed under MIT (https://github.com/wpmoo-org/ui/blob/main/LICENSE)
5
5
  */
package/dist/js/moo-ui.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Moo UI moo-ui.js v2.1.0 (https://wpmoo.org/)
2
+ * Moo UI moo-ui.js v2.1.1 (https://wpmoo.org/)
3
3
  * Copyright 2026 WPMoo Authors
4
4
  * Licensed under MIT (https://github.com/wpmoo-org/ui/blob/main/LICENSE)
5
5
  */
@@ -247,11 +247,7 @@ var Combobox = class _Combobox {
247
247
  _clearStaleSelection() {
248
248
  if (this._isMultiple) {
249
249
  this._input.value = "";
250
- this._options.forEach((option) => {
251
- option.hidden = false;
252
- });
253
- this._syncGroupVisibility();
254
- this._empty.hidden = true;
250
+ this._showAllOptions();
255
251
  return;
256
252
  }
257
253
  const selected = this._selectedOptions()[0] || null;
@@ -262,6 +258,14 @@ var Combobox = class _Combobox {
262
258
  this._clearSelection();
263
259
  this._input.value = "";
264
260
  }
261
+ _showAllOptions() {
262
+ this._options.forEach((option) => {
263
+ option.hidden = false;
264
+ });
265
+ this._syncGroupVisibility();
266
+ this._empty.hidden = true;
267
+ this._liveRegion.textContent = "";
268
+ }
265
269
  _activeOption() {
266
270
  const activeId = this._input.getAttribute("aria-activedescendant");
267
271
  if (!activeId) {
@@ -348,6 +352,7 @@ var Combobox = class _Combobox {
348
352
  if (this._hidden) {
349
353
  this._hidden.value = option.dataset.value || "";
350
354
  }
355
+ this._showAllOptions();
351
356
  this._toggleClear(true);
352
357
  this._setActiveOption(option);
353
358
  this._emitChange();
@@ -440,6 +445,12 @@ var Combobox = class _Combobox {
440
445
  }
441
446
  }
442
447
  _handleKeydown(event) {
448
+ if (event.isComposing || event.keyCode === 229) {
449
+ if (event.key === "Tab") {
450
+ this._closeMenu();
451
+ }
452
+ return;
453
+ }
443
454
  const available = this._visibleOptions();
444
455
  const current = available.findIndex(
445
456
  (option) => option.id === this._input.getAttribute("aria-activedescendant")
@@ -544,12 +555,17 @@ var ContextMenu = class _ContextMenu {
544
555
  this._bindEvents();
545
556
  }
546
557
  dispose() {
558
+ if (this._disposing) {
559
+ return;
560
+ }
561
+ this._disposing = true;
547
562
  this._listeners.forEach(({ target, type, handler, options }) => {
548
563
  target.removeEventListener(type, handler, options);
549
564
  });
550
565
  this._listeners = [];
551
- this._dropdown.dispose();
552
566
  this._syncExpanded(false);
567
+ this._dropdown.hide();
568
+ this._dropdown.dispose();
553
569
  this._invoker = null;
554
570
  this._pointerRect = null;
555
571
  instances2.delete(this._element);
@@ -661,7 +677,7 @@ var ContextMenu = class _ContextMenu {
661
677
  event.preventDefault();
662
678
  event.stopPropagation();
663
679
  const group = radioButton.dataset.contextMenuRadioGroup;
664
- this._menu.querySelectorAll(`[data-context-menu-radio-group="${group}"]`).forEach((button) => {
680
+ this._menu.querySelectorAll(`[data-context-menu-radio-group="${CSS.escape(String(group))}"]`).forEach((button) => {
665
681
  const checked = button === radioButton;
666
682
  button.classList.toggle("active", checked);
667
683
  button.setAttribute("aria-pressed", String(checked));
@@ -749,9 +765,30 @@ function ownerPortalRoot(owner) {
749
765
 
750
766
  // src/js/components/datatable.js
751
767
  var instances3 = /* @__PURE__ */ new WeakMap();
768
+ var SORT_COLLATOR = new Intl.Collator(void 0, { numeric: true, sensitivity: "base" });
769
+ var PLAIN_NUMBER = /^[-+]?(?:\d+\.?\d*|\.\d+)$/;
770
+ function sortNumber(value) {
771
+ return PLAIN_NUMBER.test(value) ? Number(value) : null;
772
+ }
773
+ function compareSortValues(a, b) {
774
+ const aNumber = sortNumber(a);
775
+ const bNumber = sortNumber(b);
776
+ if (aNumber !== null && bNumber !== null) {
777
+ return Math.sign(aNumber - bNumber);
778
+ }
779
+ if (aNumber !== null || bNumber !== null) {
780
+ return aNumber !== null ? -1 : 1;
781
+ }
782
+ return SORT_COLLATOR.compare(a, b);
783
+ }
752
784
  function normalize2(value) {
753
785
  return (value ?? "").toString().trim().toLowerCase();
754
786
  }
787
+ var ESCAPE_OWNER_SELECTOR = ".modal, .offcanvas, .dropdown-menu, .popover, [role='dialog'], [role='menu'], [role='listbox']";
788
+ function escapeBelongsElsewhere(event) {
789
+ const target = event.target;
790
+ return typeof target?.closest === "function" && (Boolean(target.closest(ESCAPE_OWNER_SELECTOR)) || target.getAttribute("aria-expanded") === "true");
791
+ }
755
792
  var DataTable = class _DataTable {
756
793
  static getInstance(element) {
757
794
  return element?.nodeType === 1 ? instances3.get(element) || null : null;
@@ -1201,7 +1238,7 @@ var DataTable = class _DataTable {
1201
1238
  );
1202
1239
  }
1203
1240
  _sortValue(row, key) {
1204
- const cell = row.element.querySelector(`:scope > [data-datatable-column="${key}"]`);
1241
+ const cell = row.element.querySelector(`:scope > [data-datatable-column="${CSS.escape(String(key))}"]`);
1205
1242
  if (!cell) {
1206
1243
  return "";
1207
1244
  }
@@ -1228,10 +1265,8 @@ var DataTable = class _DataTable {
1228
1265
  filtered.sort((a, b) => {
1229
1266
  const aValue = this._sortValue(a, this._sortKey);
1230
1267
  const bValue = this._sortValue(b, this._sortKey);
1231
- if (aValue === bValue) {
1232
- return a.index - b.index;
1233
- }
1234
- return aValue > bValue ? direction : -direction;
1268
+ const order = compareSortValues(aValue, bValue);
1269
+ return order ? order * direction : a.index - b.index;
1235
1270
  });
1236
1271
  } else {
1237
1272
  filtered.sort((a, b) => a.index - b.index);
@@ -1298,7 +1333,7 @@ var DataTable = class _DataTable {
1298
1333
  summary.appendChild(this._createFacetBadge(`${selected.size} selected`));
1299
1334
  } else {
1300
1335
  selected.forEach((value) => {
1301
- const option = facetRoot.querySelector(`[data-datatable-facet-option="${value}"]`);
1336
+ const option = facetRoot.querySelector(`[data-datatable-facet-option="${CSS.escape(String(value))}"]`);
1302
1337
  const label = option?.querySelector("[data-datatable-facet-option-label]")?.textContent ?? value;
1303
1338
  summary.appendChild(this._createFacetBadge(label));
1304
1339
  });
@@ -1527,17 +1562,17 @@ var DataTable = class _DataTable {
1527
1562
  return withEllipsis;
1528
1563
  }
1529
1564
  _isColumnFixed(key) {
1530
- return this._element.querySelector(`th[data-datatable-column="${key}"]`)?.hasAttribute("data-datatable-column-fixed") || false;
1565
+ return this._element.querySelector(`th[data-datatable-column="${CSS.escape(String(key))}"]`)?.hasAttribute("data-datatable-column-fixed") || false;
1531
1566
  }
1532
1567
  _setColumnVisible(key, visible, { syncViewToggle = true } = {}) {
1533
1568
  if (!visible && this._isColumnFixed(key)) {
1534
1569
  return;
1535
1570
  }
1536
- this._element.querySelectorAll(`[data-datatable-column="${key}"], [data-datatable-detail-column="${key}"]`).forEach((cell) => {
1571
+ this._element.querySelectorAll(`[data-datatable-column="${CSS.escape(String(key))}"], [data-datatable-detail-column="${CSS.escape(String(key))}"]`).forEach((cell) => {
1537
1572
  cell.classList.toggle("datatable-col-hidden", !visible);
1538
1573
  });
1539
1574
  if (syncViewToggle) {
1540
- this._element.querySelectorAll(`[data-datatable-column-toggle="${key}"]`).forEach((toggle) => {
1575
+ this._element.querySelectorAll(`[data-datatable-column-toggle="${CSS.escape(String(key))}"]`).forEach((toggle) => {
1541
1576
  toggle.classList.toggle("active", visible);
1542
1577
  toggle.setAttribute("aria-pressed", String(visible));
1543
1578
  });
@@ -1674,8 +1709,8 @@ var DataTable = class _DataTable {
1674
1709
  if (group) {
1675
1710
  const key = group.dataset.datatableFilterGroup;
1676
1711
  this._showFilterPickerPanel(key);
1677
- const search = this._element.querySelector(`[data-datatable-filter-option-search="${key}"]`);
1678
- const option = this._element.querySelector(`[data-datatable-filter-option-key="${key}"]`);
1712
+ const search = this._element.querySelector(`[data-datatable-filter-option-search="${CSS.escape(String(key))}"]`);
1713
+ const option = this._element.querySelector(`[data-datatable-filter-option-key="${CSS.escape(String(key))}"]`);
1679
1714
  (search || option)?.focus({ preventScroll: true });
1680
1715
  return;
1681
1716
  }
@@ -1690,7 +1725,7 @@ var DataTable = class _DataTable {
1690
1725
  }
1691
1726
  const key = search.dataset.datatableFilterOptionSearch;
1692
1727
  const query = normalize2(search.value);
1693
- this._element.querySelectorAll(`[data-datatable-filter-option-key="${key}"]`).forEach((option) => {
1728
+ this._element.querySelectorAll(`[data-datatable-filter-option-key="${CSS.escape(String(key))}"]`).forEach((option) => {
1694
1729
  const label = normalize2(option.querySelector("[data-datatable-filter-option-label]")?.textContent || option.textContent);
1695
1730
  option.closest("li")?.classList.toggle("datatable-filter-option-search-hidden", query.length > 0 && !label.includes(query));
1696
1731
  });
@@ -1707,7 +1742,7 @@ var DataTable = class _DataTable {
1707
1742
  }
1708
1743
  const key = search.dataset.datatableFilterOptionSearch;
1709
1744
  const options = Array.from(
1710
- this._element.querySelectorAll(`[data-datatable-filter-option-key="${key}"]`)
1745
+ this._element.querySelectorAll(`[data-datatable-filter-option-key="${CSS.escape(String(key))}"]`)
1711
1746
  );
1712
1747
  const firstVisible = options.find(
1713
1748
  (option) => !option.closest("li")?.classList.contains("datatable-filter-option-search-hidden")
@@ -1832,7 +1867,7 @@ var DataTable = class _DataTable {
1832
1867
  }
1833
1868
  row.element.setAttribute(`data-datatable-facet-${key}`, value);
1834
1869
  row.facets[key] = value;
1835
- const cell = row.element.querySelector(`[data-datatable-column="${key}"]`);
1870
+ const cell = row.element.querySelector(`[data-datatable-column="${CSS.escape(String(key))}"]`);
1836
1871
  if (!cell) {
1837
1872
  return;
1838
1873
  }
@@ -1846,7 +1881,7 @@ var DataTable = class _DataTable {
1846
1881
  if (currentIcon && icon) {
1847
1882
  currentIcon.replaceWith(icon.cloneNode(true));
1848
1883
  }
1849
- const cardValue = row.cardElement?.querySelector(`[data-datatable-detail-column="${key}"] .datatable-card-value`);
1884
+ const cardValue = row.cardElement?.querySelector(`[data-datatable-detail-column="${CSS.escape(String(key))}"] .datatable-card-value`);
1850
1885
  if (cardValue) {
1851
1886
  cardValue.innerHTML = cell.innerHTML;
1852
1887
  }
@@ -1940,11 +1975,11 @@ var DataTable = class _DataTable {
1940
1975
  }
1941
1976
  });
1942
1977
  this._listen(this._document, "click", (event) => this._handleSortAction(event));
1943
- this._listen(this._document, "keydown", (event) => {
1944
- if (event.key === "Escape" && this._selectedIds.size > 0) {
1978
+ this._listen(this._window, "keydown", (event) => {
1979
+ if (event.key === "Escape" && this._selectedIds.size > 0 && !escapeBelongsElsewhere(event)) {
1945
1980
  this._clearSelection();
1946
1981
  }
1947
- });
1982
+ }, { capture: true });
1948
1983
  this._listen(this._element, "show.bs.dropdown", (event) => {
1949
1984
  this._reparentRowActionMenu(event.target);
1950
1985
  this._reparentSortMenu(event.target);
@@ -2141,6 +2176,15 @@ function dispatch(element, window2, name, detail = {}, cancelable = false) {
2141
2176
  })
2142
2177
  );
2143
2178
  }
2179
+ function formDefaultValue(input) {
2180
+ if (!input) {
2181
+ return "";
2182
+ }
2183
+ if (!("datepickerFormDefault" in input.dataset)) {
2184
+ input.dataset.datepickerFormDefault = input.getAttribute("value") || "";
2185
+ }
2186
+ return input.dataset.datepickerFormDefault;
2187
+ }
2144
2188
  function setHiddenValue(input, value) {
2145
2189
  if (!input) return;
2146
2190
  input.value = value || "";
@@ -2544,6 +2588,7 @@ var MooCalendar = class _MooCalendar {
2544
2588
  ArrowUp: -7
2545
2589
  };
2546
2590
  let nextDate = null;
2591
+ let stepTowardActive = false;
2547
2592
  if (event.key in keyMap) {
2548
2593
  nextDate = addDays(this._activeDate, keyMap[event.key]);
2549
2594
  } else if (event.key === "Home") {
@@ -2554,10 +2599,13 @@ var MooCalendar = class _MooCalendar {
2554
2599
  const weekStart = firstDayOfWeek(this._config.locale);
2555
2600
  const weekdayOffset = (this._activeDate.getDay() - weekStart + 7) % 7;
2556
2601
  nextDate = addDays(this._activeDate, 6 - weekdayOffset);
2557
- } else if (event.key === "PageUp") {
2558
- nextDate = addMonths(this._activeDate, -1);
2559
- } else if (event.key === "PageDown") {
2560
- nextDate = addMonths(this._activeDate, 1);
2602
+ } else if (event.key === "PageUp" || event.key === "PageDown") {
2603
+ const target = addMonths(this._activeDate, event.key === "PageUp" ? -1 : 1);
2604
+ const { minDate, maxDate } = this._config;
2605
+ nextDate = limitToRange(target, minDate, maxDate);
2606
+ stepTowardActive = [minDate, maxDate].some(
2607
+ (edge) => edge && compareDates(nextDate, edge) === 0
2608
+ );
2561
2609
  } else if (event.key === "Enter" || event.key === " " || event.key === "Spacebar") {
2562
2610
  event.preventDefault();
2563
2611
  this._selectDate(this._activeDate, true);
@@ -2566,7 +2614,8 @@ var MooCalendar = class _MooCalendar {
2566
2614
  return;
2567
2615
  }
2568
2616
  event.preventDefault();
2569
- this._setActiveDate(nextDate, true, compareDates(nextDate, this._activeDate) < 0 ? -1 : 1);
2617
+ const backward = compareDates(nextDate, this._activeDate) < 0;
2618
+ this._setActiveDate(nextDate, true, backward !== stepTowardActive ? -1 : 1);
2570
2619
  }
2571
2620
  _setActiveDate(date, focus = false, step = 0) {
2572
2621
  const nextDate = step === 0 ? this._nearestEnabledDate(date) : this._nextEnabledDate(date, step);
@@ -2832,7 +2881,7 @@ var MooDatepicker = class _MooDatepicker {
2832
2881
  value: config.value || this._input.value || element.dataset.datepickerValue
2833
2882
  });
2834
2883
  this._placeholder = this._config.placeholder;
2835
- this._defaultValue = this._input.defaultValue || this._input.getAttribute("value") || "";
2884
+ this._defaultValue = formDefaultValue(this._input);
2836
2885
  this.calendar = MooCalendar.getOrCreateInstance(this._calendarRoot, {
2837
2886
  ...this._config,
2838
2887
  mode: "single",
@@ -2997,8 +3046,8 @@ var MooDateRangePicker = class _MooDateRangePicker {
2997
3046
  endValue: config.endValue || this._endInput.value || element.dataset.datepickerEndValue
2998
3047
  });
2999
3048
  this._placeholder = this._config.placeholder;
3000
- this._defaultStartValue = this._startInput.defaultValue || this._startInput.getAttribute("value") || "";
3001
- this._defaultEndValue = this._endInput.defaultValue || this._endInput.getAttribute("value") || "";
3049
+ this._defaultStartValue = formDefaultValue(this._startInput);
3050
+ this._defaultEndValue = formDefaultValue(this._endInput);
3002
3051
  this.calendar = MooCalendar.getOrCreateInstance(this._calendarRoot, this._config);
3003
3052
  rangePickerInstances.set(element, this);
3004
3053
  this._syncFromCalendar();
@@ -3143,6 +3192,13 @@ var MooDateRangePicker = class _MooDateRangePicker {
3143
3192
 
3144
3193
  // src/js/components/sidebar.js
3145
3194
  var instances4 = /* @__PURE__ */ new WeakMap();
3195
+ var FLYOUT_FOCUSABLE_SELECTOR = "a[href], button, input, select, textarea, [tabindex]";
3196
+ function flyoutFocusables(flyout) {
3197
+ const view = flyout.ownerDocument.defaultView;
3198
+ return [...flyout.querySelectorAll(FLYOUT_FOCUSABLE_SELECTOR)].filter(
3199
+ (element) => !element.matches(":disabled") && element.tabIndex >= 0 && !element.closest("[hidden], [inert]") && element.getClientRects().length > 0 && view.getComputedStyle(element).visibility === "visible"
3200
+ );
3201
+ }
3146
3202
  var Sidebar = class _Sidebar {
3147
3203
  static getInstance(element) {
3148
3204
  return element?.nodeType === 1 ? instances4.get(element) || null : null;
@@ -3570,7 +3626,37 @@ var Sidebar = class _Sidebar {
3570
3626
  this._closeFlyouts();
3571
3627
  } else {
3572
3628
  this._openFlyout(item);
3629
+ if (event.detail === 0) {
3630
+ if (this._flyout) {
3631
+ flyoutFocusables(this._flyout)[0]?.focus();
3632
+ }
3633
+ }
3634
+ }
3635
+ }
3636
+ // The flyout lives in a portal, away from its trigger, so Escape and Tab
3637
+ // out of it return to the trigger instead of wandering. Tab between its
3638
+ // items stays native; a key a flyout control already handled is left alone.
3639
+ _handleFlyoutKeydown(event) {
3640
+ const owner = this._flyoutOwner;
3641
+ if (event.defaultPrevented || !this._flyout || !owner || !(event.key === "Escape" || event.key === "Tab")) {
3642
+ return false;
3643
+ }
3644
+ const inFlyout = this._flyout.contains(event.target);
3645
+ if (!inFlyout && !(event.key === "Escape" && owner.contains(event.target))) {
3646
+ return false;
3647
+ }
3648
+ if (event.key === "Tab") {
3649
+ const items = flyoutFocusables(this._flyout);
3650
+ const edge = event.shiftKey ? items[0] : items[items.length - 1];
3651
+ if (edge && event.target !== edge) {
3652
+ return false;
3653
+ }
3573
3654
  }
3655
+ event.preventDefault();
3656
+ const trigger = owner.querySelector(":scope > .sidebar-menu-sub-trigger");
3657
+ this._closeFlyouts();
3658
+ trigger?.focus();
3659
+ return true;
3574
3660
  }
3575
3661
  _handleOutsideFlyoutClick(event) {
3576
3662
  if (!this._flyout) {
@@ -3583,6 +3669,9 @@ var Sidebar = class _Sidebar {
3583
3669
  }
3584
3670
  }
3585
3671
  _handleShortcut(event) {
3672
+ if (this._handleFlyoutKeydown(event)) {
3673
+ return;
3674
+ }
3586
3675
  const target = event.target;
3587
3676
  const isEditable = target instanceof this._window.Element && (target.matches("input, textarea, select") || target.isContentEditable);
3588
3677
  if (event.defaultPrevented || event.isComposing || isEditable || !this._config.keyboard || !(event.metaKey || event.ctrlKey) || event.key.toLowerCase() !== "b" || !this._isDesktop()) {