basecoat-cli 0.2.2 → 0.2.4
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.
- package/dist/assets/jinja/dropdown-menu.html.jinja +1 -1
- package/dist/assets/jinja/select.html.jinja +19 -17
- package/dist/assets/js/all.js +197 -101
- package/dist/assets/js/all.min.js +1 -1
- package/dist/assets/js/dropdown-menu.js +50 -29
- package/dist/assets/js/dropdown-menu.min.js +1 -1
- package/dist/assets/js/popover.js +22 -7
- package/dist/assets/js/popover.min.js +1 -1
- package/dist/assets/js/select.js +95 -41
- package/dist/assets/js/select.min.js +1 -1
- package/dist/assets/js/sidebar.js +16 -10
- package/dist/assets/js/sidebar.min.js +1 -1
- package/dist/assets/js/tabs.js +6 -6
- package/dist/assets/js/toast.js +8 -8
- package/dist/assets/js/toast.min.js +1 -1
- package/dist/assets/nunjucks/dropdown-menu.njk +1 -1
- package/dist/assets/nunjucks/select.njk +1 -1
- package/package.json +1 -1
- package/dist/assets/js/dark-mode.js +0 -10
- package/dist/assets/js/dark-mode.min.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{const e=e=>{const t=e.querySelector(":scope > button"),a=e.querySelector(":scope > [data-popover]"),n=a.querySelector('[role="menu"]');if(!t||!n||!a)return void console.error("Dropdown menu component is missing a trigger, a menu, or a popover content element.",e);let r=[],i=-1;const o=()=>{"false"!==t.getAttribute("aria-expanded")&&(t.setAttribute("aria-expanded","false"),t.removeAttribute("aria-activedescendant"),a.setAttribute("aria-hidden","true"),t.focus(),i=-1)},d=()=>{t.setAttribute("aria-expanded","true"),a.setAttribute("aria-hidden","false"),r=Array.from(n.querySelectorAll('[role^="menuitem"]:not([disabled])')),r.length>0&&s(0)},s=e=>{if(i>-1&&r[i]&&r[i].classList.remove("active"),i=e,i>-1&&r[i]){const e=r[i];e.classList.add("active"),t.setAttribute("aria-activedescendant",e.id)}else t.removeAttribute("aria-activedescendant")};t.addEventListener("click",(()=>{"true"===t.getAttribute("aria-expanded")?o():d()})),e.addEventListener("keydown",(e=>{const a="true"===t.getAttribute("aria-expanded");if("Escape"===e.key)return void(a&&o());if(!a)return void(["ArrowDown","ArrowUp","Enter"," "].includes(e.key)&&(e.preventDefault(),d()));if(0===r.length)return;let n=i;switch(e.key){case"ArrowDown":e.preventDefault(),n=i<r.length-1?i+1:0;break;case"ArrowUp":e.preventDefault(),n=i>0?i-1:r.length-1;break;case"Home":e.preventDefault(),n=0;break;case"End":e.preventDefault(),n=r.length-1;break;case"Enter":case" ":return e.preventDefault(),r[i]?.click(),void o()}n!==i&&s(n)})),n.addEventListener("click",(e=>{e.target.closest('[role^="menuitem"]')&&o()})),document.addEventListener("click",(t=>{e.contains(t.target)||o()})),e.dataset.dropdownMenuInitialized=!0};document.querySelectorAll(".dropdown-menu:not([data-dropdown-menu-initialized])").forEach(e);new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches(".dropdown-menu:not([data-dropdown-menu-initialized])")&&e(t),t.querySelectorAll(".dropdown-menu:not([data-dropdown-menu-initialized])").forEach(e))}))}))})).observe(document.body,{childList:!0,subtree:!0})})(),(()=>{const e=e=>{const t=e.querySelector(":scope > button"),a=e.querySelector(":scope > [data-popover]");if(!t||!a)return void console.error("Popover component is missing a trigger button or a content element.",e);const n=()=>{"false"!==t.getAttribute("aria-expanded")&&(t.setAttribute("aria-expanded","false"),a.setAttribute("aria-hidden","true"),t.focus())};t.addEventListener("click",(()=>{"true"===t.getAttribute("aria-expanded")?n():(()=>{const e=a.querySelector("[autofocus]");e&&a.addEventListener("transitionend",(()=>{e.focus()}),{once:!0}),t.setAttribute("aria-expanded","true"),a.setAttribute("aria-hidden","false")})()})),e.addEventListener("keydown",(e=>{"Escape"===e.key&&n()})),document.addEventListener("click",(t=>{e.contains(t.target)||n()})),e.dataset.popoverInitialized=!0};document.querySelectorAll(".popover:not([data-popover-initialized])").forEach(e);new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches(".popover:not([data-popover-initialized])")&&e(t),t.querySelectorAll(".popover:not([data-popover-initialized])").forEach(e))}))}))})).observe(document.body,{childList:!0,subtree:!0})})(),(()=>{const e=e=>{const t=e.querySelector(":scope > button"),a=t.querySelector(":scope > span"),n=e.querySelector(":scope > [data-popover]"),r=n.querySelector('[role="listbox"]'),i=e.querySelector(':scope > input[type="hidden"]'),o=e.querySelector('header input[type="text"]');if(!(t&&n&&r&&i))return;const d=Array.from(r.querySelectorAll('[role="option"]'));let s=[...d],c=-1;const l=e=>{e&&(a.innerHTML=e.dataset.label||e.innerHTML,i.value=e.dataset.value,r.querySelector('[role="option"][aria-selected="true"]')?.removeAttribute("aria-selected"),e.setAttribute("aria-selected","true"))},u=()=>{n.setAttribute("aria-hidden","true"),t.setAttribute("aria-expanded","false"),o&&(o.value="",s=[...d],d.forEach((e=>e.setAttribute("aria-hidden","false")))),t.removeAttribute("aria-activedescendant"),c>-1&&d[c]?.classList.remove("active"),c=-1},h=e=>{e&&(e.dataset.value&&l(e),u())};if(o){const e=()=>{const e=o.value.trim().toLowerCase();c>-1&&(d[c].classList.remove("active"),t.removeAttribute("aria-activedescendant"),c=-1),s=[],d.forEach((t=>{const a=(t.dataset.label||t.textContent).trim().toLowerCase().includes(e);t.setAttribute("aria-hidden",String(!a)),a&&s.push(t)}))};o.addEventListener("input",e)}let v=d.find((e=>i.value&&e.dataset.value===i.value));!v&&d.length>0&&(v=d[0]),l(v);const p=e=>{const a="false"===n.getAttribute("aria-hidden");if(!["ArrowDown","ArrowUp","Enter","Home","End","Escape"].includes(e.key))return;if(!a)return void("Enter"!==e.key&&"Escape"!==e.key&&(e.preventDefault(),t.click()));if(e.preventDefault(),"Escape"===e.key)return void u();if("Enter"===e.key)return void(c>-1&&h(s[c]));if(0===s.length)return;const r=c>-1?s.indexOf(d[c]):-1;let i=r;switch(e.key){case"ArrowDown":r<s.length-1&&(i=r+1);break;case"ArrowUp":r>0?i=r-1:-1===r&&(i=0);break;case"Home":i=0;break;case"End":i=s.length-1}if(i!==r){r>-1&&s[r].classList.remove("active");const e=s[i];e.classList.add("active"),c=d.indexOf(e),e.id&&t.setAttribute("aria-activedescendant",e.id),e.scrollIntoView({block:"nearest",behavior:"smooth"})}};t.addEventListener("keydown",p),o&&o.addEventListener("keydown",p),t.addEventListener("click",(()=>{if("true"===t.getAttribute("aria-expanded"))u();else{n.setAttribute("aria-hidden","false"),t.setAttribute("aria-expanded","true"),o&&o.focus();const e=r.querySelector('[role="option"][aria-selected="true"]');e&&(c>-1&&d[c]?.classList.remove("active"),c=d.indexOf(e),e.classList.add("active"),e.id&&t.setAttribute("aria-activedescendant",e.id),e.scrollIntoView({block:"nearest"}))}})),r.addEventListener("click",(e=>{const t=e.target.closest('[role="option"]');t&&h(t)})),document.addEventListener("click",(t=>{e.contains(t.target)||u()})),n.setAttribute("aria-hidden","true"),e.dataset.selectInitialized=!0};document.querySelectorAll("div.select:not([data-select-initialized])").forEach(e);new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches("div.select:not([data-select-initialized])")&&e(t),t.querySelectorAll("div.select:not([data-select-initialized])").forEach(e))}))}))})).observe(document.body,{childList:!0,subtree:!0})})(),(()=>{if(!window.history.__basecoatPatched){const e=window.history.pushState;window.history.pushState=function(...t){e.apply(this,t),window.dispatchEvent(new Event("basecoat:locationchange"))};const t=window.history.replaceState;window.history.replaceState=function(...e){t.apply(this,e),window.dispatchEvent(new Event("basecoat:locationchange"))},window.history.__basecoatPatched=!0}const e=e=>{const t="false"!==e.dataset.initialOpen,a="true"===e.dataset.initialMobileOpen,n=parseInt(e.dataset.breakpoint)||768;let r=n>0?window.innerWidth>=n?t:a:t;const i=()=>{const t=window.location.pathname.replace(/\/$/,"");e.querySelectorAll("a").forEach((e=>{if(e.hasAttribute("data-ignore-current"))return;new URL(e.href).pathname.replace(/\/$/,"")===t?e.setAttribute("aria-current","page"):e.removeAttribute("aria-current")}))},o=()=>{e.setAttribute("aria-hidden",!r),r?e.removeAttribute("inert"):e.setAttribute("inert","")},d=e=>{r=e,o()},s=e.id;window.addEventListener("sidebar:open",(e=>{e.detail?.id&&e.detail.id!==s||d(!0)})),window.addEventListener("sidebar:close",(e=>{e.detail?.id&&e.detail.id!==s||d(!1)})),window.addEventListener("sidebar:toggle",(e=>{e.detail?.id&&e.detail.id!==s||d(!r)})),e.addEventListener("click",(t=>{const a=t.target,r=e.querySelector("nav");if(window.innerWidth<n&&a.closest("a, button")&&!a.closest("[data-keep-mobile-sidebar-open]"))return document.activeElement&&document.activeElement.blur(),void d(!1);(a===e||r&&!r.contains(a))&&(document.activeElement&&document.activeElement.blur(),d(!1))})),window.addEventListener("popstate",i),window.addEventListener("basecoat:locationchange",i),o(),i(),e.dataset.sidebarInitialized=!0};document.querySelectorAll(".sidebar:not([data-sidebar-initialized])").forEach(e);new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches(".sidebar:not([data-sidebar-initialized])")&&e(t),t.querySelectorAll(".sidebar:not([data-sidebar-initialized])").forEach(e))}))}))})).observe(document.body,{childList:!0,subtree:!0})})(),(()=>{const e=e=>{const t=e.querySelector('[role="tablist"]');if(!t)return;const a=Array.from(t.querySelectorAll('[role="tab"]')),n=a.map((e=>document.getElementById(e.getAttribute("aria-controls")))).filter(Boolean),r=e=>{a.forEach(((e,t)=>{e.setAttribute("aria-selected","false"),e.setAttribute("tabindex","-1"),n[t]&&(n[t].hidden=!0)})),e.setAttribute("aria-selected","true"),e.setAttribute("tabindex","0");const t=document.getElementById(e.getAttribute("aria-controls"));t&&(t.hidden=!1)};t.addEventListener("click",(e=>{const t=e.target.closest('[role="tab"]');t&&r(t)})),t.addEventListener("keydown",(e=>{const t=e.target;if(!a.includes(t))return;let n;const i=a.indexOf(t);switch(e.key){case"ArrowRight":n=a[(i+1)%a.length];break;case"ArrowLeft":n=a[(i-1+a.length)%a.length];break;case"Home":n=a[0];break;case"End":n=a[a.length-1];break;default:return}e.preventDefault(),r(n),n.focus()})),e.dataset.tabsInitialized=!0};document.querySelectorAll(".tabs:not([data-tabs-initialized])").forEach(e);new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches(".tabs:not([data-tabs-initialized])")&&e(t),t.querySelectorAll(".tabs:not([data-tabs-initialized])").forEach(e))}))}))})).observe(document.body,{childList:!0,subtree:!0})})(),(()=>{let e;const t=new WeakMap;let a=!1;const n={success:'<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="m9 12 2 2 4-4"/></svg>',error:'<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="m15 9-6 6"/><path d="m9 9 6 6"/></svg>',info:'<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 16v-4"/><path d="M12 8h.01"/></svg>',warning:'<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"/><path d="M12 9v4"/><path d="M12 17h.01"/></svg>'};function r(t){t.dataset.toasterInitialized||(e=t,e.addEventListener("mouseenter",o),e.addEventListener("mouseleave",d),e.addEventListener("click",(e=>{const t=e.target.closest(".toast footer a"),a=e.target.closest(".toast footer button");(t||a)&&s(e.target.closest(".toast"))})),e.querySelectorAll(".toast:not([data-toast-initialized])").forEach(i),e.dataset.toasterInitialized="true")}function i(e){if(e.dataset.toastInitialized)return;const n=parseInt(e.dataset.duration),r=-1!==n?n||("error"===e.dataset.category?5e3:3e3):-1,i={remainingTime:r,timeoutId:null,startTime:null};-1!==r&&(a?i.timeoutId=null:(i.startTime=Date.now(),i.timeoutId=setTimeout((()=>s(e)),r))),t.set(e,i),e.dataset.toastInitialized="true"}function o(){a||(a=!0,e.querySelectorAll('.toast:not([aria-hidden="true"])').forEach((e=>{if(!t.has(e))return;const a=t.get(e);a.timeoutId&&(clearTimeout(a.timeoutId),a.timeoutId=null,a.remainingTime-=Date.now()-a.startTime)})))}function d(){a&&(a=!1,e.querySelectorAll('.toast:not([aria-hidden="true"])').forEach((e=>{if(!t.has(e))return;const a=t.get(e);-1===a.remainingTime||a.timeoutId||(a.remainingTime>0?(a.startTime=Date.now(),a.timeoutId=setTimeout((()=>s(e)),a.remainingTime)):s(e))})))}function s(e){if(!t.has(e))return;const a=t.get(e);clearTimeout(a.timeoutId),t.delete(e),document.activeElement&&document.activeElement.blur(),e.setAttribute("aria-hidden","true"),e.addEventListener("transitionend",(()=>e.remove()),{once:!0})}const c=document.getElementById("toaster");c&&r(c),window.addEventListener("basecoat:toast",(t=>{if(!e)return void console.error("Cannot create toast: toaster container not found on page.");const a=function(e){const{category:t="info",title:a,description:r,action:i,cancel:o,duration:d,icon:s}=e,c=s||t&&n[t]||"",l=a?`<h2>${a}</h2>`:"",u=r?`<p>${r}</p>`:"",h=i?.href?`<a href="${i.href}" class="btn" data-toast-action>${i.label}</a>`:i?.onclick?`<button type="button" class="btn" data-toast-action onclick="${i.onclick}">${i.label}</button>`:"",v=o?`<button type="button" class="btn-outline h-6 text-xs px-2.5 rounded-sm" data-toast-cancel onclick="${o?.onclick}">${o.label}</button>`:"",p=`\n <div\n class="toast"\n role="${"error"===t?"alert":"status"}"\n aria-atomic="true"\n ${t?`data-category="${t}"`:""}\n ${void 0!==d?`data-duration="${d}"`:""}\n >\n <div class="toast-content">\n ${c}\n <section>\n ${l}\n ${u}\n </section>\n ${h||v?`<footer>${h}${v}</footer>`:""}\n </div>\n </div>\n </div>\n `,b=document.createElement("template");return b.innerHTML=p.trim(),b.content.firstChild}(t.detail?.config||{});e.appendChild(a)}));new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches("#toaster")&&r(t),e&&t.matches(".toast:not([data-toast-initialized])")&&i(t))}))}))})).observe(document.body,{childList:!0,subtree:!0})})();
|
|
1
|
+
(()=>{const e=e=>{const t=e.querySelector(":scope > button"),a=e.querySelector(":scope > [data-popover]"),n=a.querySelector('[role="menu"]');if(!t||!n||!a){const r=[];return t||r.push("trigger"),n||r.push("menu"),a||r.push("popover"),void console.error(`Dropdown menu initialisation failed. Missing element(s): ${r.join(", ")}`,e)}let r=[],i=-1;const o=(e=!0)=>{"false"!==t.getAttribute("aria-expanded")&&(t.setAttribute("aria-expanded","false"),t.removeAttribute("aria-activedescendant"),a.setAttribute("aria-hidden","true"),e&&t.focus(),d(-1))},s=()=>{document.dispatchEvent(new CustomEvent("basecoat:popover",{detail:{source:e}})),t.setAttribute("aria-expanded","true"),a.setAttribute("aria-hidden","false"),r=Array.from(n.querySelectorAll('[role^="menuitem"]')).filter((e=>!e.hasAttribute("disabled")&&"true"!==e.getAttribute("aria-disabled"))),r.length>0&&d(0)},d=e=>{if(i>-1&&r[i]&&r[i].classList.remove("active"),i=e,i>-1&&r[i]){const e=r[i];e.classList.add("active"),t.setAttribute("aria-activedescendant",e.id)}else t.removeAttribute("aria-activedescendant")};t.addEventListener("click",(()=>{"true"===t.getAttribute("aria-expanded")?o():s()})),e.addEventListener("keydown",(e=>{const a="true"===t.getAttribute("aria-expanded");if("Escape"===e.key)return void(a&&o());if(!a)return void(["ArrowDown","ArrowUp","Enter"," "].includes(e.key)&&(e.preventDefault(),s()));if(0===r.length)return;let n=i;switch(e.key){case"ArrowDown":e.preventDefault(),n=Math.min(i+1,r.length-1);break;case"ArrowUp":e.preventDefault(),n=Math.max(i-1,0);break;case"Home":e.preventDefault(),n=0;break;case"End":e.preventDefault(),n=r.length-1;break;case"Enter":case" ":return e.preventDefault(),r[i]?.click(),void o()}n!==i&&d(n)})),n.addEventListener("click",(e=>{e.target.closest('[role^="menuitem"]')&&o()})),document.addEventListener("click",(t=>{e.contains(t.target)||o()})),document.addEventListener("basecoat:popover",(t=>{t.detail.source!==e&&o(!1)})),e.dataset.dropdownMenuInitialized=!0};document.querySelectorAll(".dropdown-menu:not([data-dropdown-menu-initialized])").forEach(e);new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches(".dropdown-menu:not([data-dropdown-menu-initialized])")&&e(t),t.querySelectorAll(".dropdown-menu:not([data-dropdown-menu-initialized])").forEach(e))}))}))})).observe(document.body,{childList:!0,subtree:!0})})(),(()=>{const e=e=>{const t=e.querySelector(":scope > button"),a=e.querySelector(":scope > [data-popover]");if(!t||!a){const n=[];return t||n.push("trigger"),a||n.push("content"),void console.error(`Popover initialisation failed. Missing element(s): ${n.join(", ")}`,e)}const n=(e=!0)=>{"false"!==t.getAttribute("aria-expanded")&&(t.setAttribute("aria-expanded","false"),a.setAttribute("aria-hidden","true"),e&&t.focus())};t.addEventListener("click",(()=>{"true"===t.getAttribute("aria-expanded")?n():(()=>{document.dispatchEvent(new CustomEvent("basecoat:popover",{detail:{source:e}}));const n=a.querySelector("[autofocus]");n&&a.addEventListener("transitionend",(()=>{n.focus()}),{once:!0}),t.setAttribute("aria-expanded","true"),a.setAttribute("aria-hidden","false")})()})),e.addEventListener("keydown",(e=>{"Escape"===e.key&&n()})),document.addEventListener("click",(t=>{e.contains(t.target)||n()})),document.addEventListener("basecoat:popover",(t=>{t.detail.source!==e&&n(!1)})),e.dataset.popoverInitialized=!0};document.querySelectorAll(".popover:not([data-popover-initialized])").forEach(e);new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches(".popover:not([data-popover-initialized])")&&e(t),t.querySelectorAll(".popover:not([data-popover-initialized])").forEach(e))}))}))})).observe(document.body,{childList:!0,subtree:!0})})(),(()=>{const e=e=>{const t=e.querySelector(":scope > button"),a=t.querySelector(":scope > span"),n=e.querySelector(":scope > [data-popover]"),r=n.querySelector('[role="listbox"]'),i=e.querySelector(':scope > input[type="hidden"]'),o=e.querySelector('header input[type="text"]');if(!(t&&n&&r&&i)){const a=[];return t||a.push("trigger"),n||a.push("popover"),r||a.push("listbox"),i||a.push("input"),void console.error(`Select component initialisation failed. Missing element(s): ${a.join(", ")}`,e)}const s=Array.from(r.querySelectorAll('[role="option"]'));let d=[...s],c=-1;const l=()=>{const e=getComputedStyle(n);return parseFloat(e.transitionDuration)>0||parseFloat(e.transitionDelay)>0},u=e=>{e&&(a.innerHTML=e.dataset.label||e.innerHTML,i.value=e.dataset.value,r.querySelector('[role="option"][aria-selected="true"]')?.removeAttribute("aria-selected"),e.setAttribute("aria-selected","true"))},p=(e=!0)=>{if("true"!==n.getAttribute("aria-hidden")){if(o){const e=()=>{o.value="",d=[...s],s.forEach((e=>e.setAttribute("aria-hidden","false")))};l()?n.addEventListener("transitionend",e,{once:!0}):e()}e&&t.focus(),n.setAttribute("aria-hidden","true"),t.setAttribute("aria-expanded","false"),t.removeAttribute("aria-activedescendant"),c>-1&&s[c]?.classList.remove("active"),c=-1}},h=t=>{if(!t)return;null!=t.dataset.value&&u(t),p();const a=new CustomEvent("change",{detail:{value:t.dataset.value},bubbles:!0});e.dispatchEvent(a)};if(o){const e=()=>{const e=o.value.trim().toLowerCase();c>-1&&(s[c].classList.remove("active"),t.removeAttribute("aria-activedescendant"),c=-1),d=[],s.forEach((t=>{const a=(t.dataset.label||t.textContent).trim().toLowerCase().includes(e);t.setAttribute("aria-hidden",String(!a)),a&&d.push(t)}))};o.addEventListener("input",e)}let v=s.find((e=>e.dataset.value===i.value));!v&&s.length>0&&(v=s[0]),u(v);const b=e=>{const a="false"===n.getAttribute("aria-hidden");if(!["ArrowDown","ArrowUp","Enter","Home","End","Escape"].includes(e.key))return;if(!a)return void("Enter"!==e.key&&"Escape"!==e.key&&(e.preventDefault(),t.click()));if(e.preventDefault(),"Escape"===e.key)return void p();if("Enter"===e.key)return void(c>-1&&h(s[c]));if(0===d.length)return;const r=c>-1?d.indexOf(s[c]):-1;let i=r;switch(e.key){case"ArrowDown":r<d.length-1&&(i=r+1);break;case"ArrowUp":r>0?i=r-1:-1===r&&(i=0);break;case"Home":i=0;break;case"End":i=d.length-1}if(i!==r){r>-1&&d[r].classList.remove("active");const e=d[i];e.classList.add("active"),c=s.indexOf(e),e.id&&t.setAttribute("aria-activedescendant",e.id),e.scrollIntoView({block:"nearest",behavior:"smooth"})}};t.addEventListener("keydown",b),o&&o.addEventListener("keydown",b);t.addEventListener("click",(()=>{"true"===t.getAttribute("aria-expanded")?p():(()=>{document.dispatchEvent(new CustomEvent("basecoat:popover",{detail:{source:e}})),o&&(l()?n.addEventListener("transitionend",(()=>{o.focus()}),{once:!0}):o.focus()),n.setAttribute("aria-hidden","false"),t.setAttribute("aria-expanded","true");const a=r.querySelector('[role="option"][aria-selected="true"]');a&&(c>-1&&s[c]?.classList.remove("active"),c=s.indexOf(a),a.classList.add("active"),a.id&&t.setAttribute("aria-activedescendant",a.id),a.scrollIntoView({block:"nearest"}))})()})),r.addEventListener("click",(e=>{const t=e.target.closest('[role="option"]');t&&h(t)})),document.addEventListener("click",(t=>{e.contains(t.target)||p(!1)})),document.addEventListener("basecoat:popover",(t=>{t.detail.source!==e&&p(!1)})),n.setAttribute("aria-hidden","true"),e.dataset.selectInitialized=!0};document.querySelectorAll("div.select:not([data-select-initialized])").forEach(e);new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches("div.select:not([data-select-initialized])")&&e(t),t.querySelectorAll("div.select:not([data-select-initialized])").forEach(e))}))}))})).observe(document.body,{childList:!0,subtree:!0})})(),(()=>{if(!window.history.__basecoatPatched){const e=window.history.pushState;window.history.pushState=function(...t){e.apply(this,t),window.dispatchEvent(new Event("basecoat:locationchange"))};const t=window.history.replaceState;window.history.replaceState=function(...e){t.apply(this,e),window.dispatchEvent(new Event("basecoat:locationchange"))},window.history.__basecoatPatched=!0}const e=e=>{const t="false"!==e.dataset.initialOpen,a="true"===e.dataset.initialMobileOpen,n=parseInt(e.dataset.breakpoint)||768;let r=n>0?window.innerWidth>=n?t:a:t;const i=()=>{const t=window.location.pathname.replace(/\/$/,"");e.querySelectorAll("a").forEach((e=>{if(e.hasAttribute("data-ignore-current"))return;new URL(e.href).pathname.replace(/\/$/,"")===t?e.setAttribute("aria-current","page"):e.removeAttribute("aria-current")}))},o=()=>{e.setAttribute("aria-hidden",!r),r?e.removeAttribute("inert"):e.setAttribute("inert","")},s=e=>{r=e,o()},d=e.id;document.addEventListener("basecoat:sidebar",(e=>{if(!e.detail?.id||e.detail.id===d)switch(e.detail?.action){case"open":s(!0);break;case"close":s(!1);break;default:s(!r)}})),e.addEventListener("click",(t=>{const a=t.target,r=e.querySelector("nav");if(window.innerWidth<n&&a.closest("a, button")&&!a.closest("[data-keep-mobile-sidebar-open]"))return document.activeElement&&document.activeElement.blur(),void s(!1);(a===e||r&&!r.contains(a))&&(document.activeElement&&document.activeElement.blur(),s(!1))})),window.addEventListener("popstate",i),window.addEventListener("basecoat:locationchange",i),o(),i(),e.dataset.sidebarInitialized=!0};document.querySelectorAll(".sidebar:not([data-sidebar-initialized])").forEach(e);new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches(".sidebar:not([data-sidebar-initialized])")&&e(t),t.querySelectorAll(".sidebar:not([data-sidebar-initialized])").forEach(e))}))}))})).observe(document.body,{childList:!0,subtree:!0})})(),(()=>{const e=e=>{const t=e.querySelector('[role="tablist"]');if(!t)return;const a=Array.from(t.querySelectorAll('[role="tab"]')),n=a.map((e=>document.getElementById(e.getAttribute("aria-controls")))).filter(Boolean),r=e=>{a.forEach(((e,t)=>{e.setAttribute("aria-selected","false"),e.setAttribute("tabindex","-1"),n[t]&&(n[t].hidden=!0)})),e.setAttribute("aria-selected","true"),e.setAttribute("tabindex","0");const t=document.getElementById(e.getAttribute("aria-controls"));t&&(t.hidden=!1)};t.addEventListener("click",(e=>{const t=e.target.closest('[role="tab"]');t&&r(t)})),t.addEventListener("keydown",(e=>{const t=e.target;if(!a.includes(t))return;let n;const i=a.indexOf(t);switch(e.key){case"ArrowRight":n=a[(i+1)%a.length];break;case"ArrowLeft":n=a[(i-1+a.length)%a.length];break;case"Home":n=a[0];break;case"End":n=a[a.length-1];break;default:return}e.preventDefault(),r(n),n.focus()})),e.dataset.tabsInitialized=!0};document.querySelectorAll(".tabs:not([data-tabs-initialized])").forEach(e);new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches(".tabs:not([data-tabs-initialized])")&&e(t),t.querySelectorAll(".tabs:not([data-tabs-initialized])").forEach(e))}))}))})).observe(document.body,{childList:!0,subtree:!0})})(),(()=>{let e;const t=new WeakMap;let a=!1;const n={success:'<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="m9 12 2 2 4-4"/></svg>',error:'<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="m15 9-6 6"/><path d="m9 9 6 6"/></svg>',info:'<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 16v-4"/><path d="M12 8h.01"/></svg>',warning:'<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"/><path d="M12 9v4"/><path d="M12 17h.01"/></svg>'};function r(t){t.dataset.toasterInitialized||(e=t,e.addEventListener("mouseenter",o),e.addEventListener("mouseleave",s),e.addEventListener("click",(e=>{const t=e.target.closest(".toast footer a"),a=e.target.closest(".toast footer button");(t||a)&&d(e.target.closest(".toast"))})),e.querySelectorAll(".toast:not([data-toast-initialized])").forEach(i),e.dataset.toasterInitialized="true")}function i(e){if(e.dataset.toastInitialized)return;const n=parseInt(e.dataset.duration),r=-1!==n?n||("error"===e.dataset.category?5e3:3e3):-1,i={remainingTime:r,timeoutId:null,startTime:null};-1!==r&&(a?i.timeoutId=null:(i.startTime=Date.now(),i.timeoutId=setTimeout((()=>d(e)),r))),t.set(e,i),e.dataset.toastInitialized="true"}function o(){a||(a=!0,e.querySelectorAll('.toast:not([aria-hidden="true"])').forEach((e=>{if(!t.has(e))return;const a=t.get(e);a.timeoutId&&(clearTimeout(a.timeoutId),a.timeoutId=null,a.remainingTime-=Date.now()-a.startTime)})))}function s(){a&&(a=!1,e.querySelectorAll('.toast:not([aria-hidden="true"])').forEach((e=>{if(!t.has(e))return;const a=t.get(e);-1===a.remainingTime||a.timeoutId||(a.remainingTime>0?(a.startTime=Date.now(),a.timeoutId=setTimeout((()=>d(e)),a.remainingTime)):d(e))})))}function d(e){if(!t.has(e))return;const a=t.get(e);clearTimeout(a.timeoutId),t.delete(e),document.activeElement&&document.activeElement.blur(),e.setAttribute("aria-hidden","true"),e.addEventListener("transitionend",(()=>e.remove()),{once:!0})}const c=document.getElementById("toaster");c&&r(c),document.addEventListener("basecoat:toast",(t=>{if(!e)return void console.error("Cannot create toast: toaster container not found on page.");const a=function(e){const{category:t="info",title:a,description:r,action:i,cancel:o,duration:s,icon:d}=e,c=d||t&&n[t]||"",l=a?`<h2>${a}</h2>`:"",u=r?`<p>${r}</p>`:"",p=i?.href?`<a href="${i.href}" class="btn" data-toast-action>${i.label}</a>`:i?.onclick?`<button type="button" class="btn" data-toast-action onclick="${i.onclick}">${i.label}</button>`:"",h=o?`<button type="button" class="btn-outline h-6 text-xs px-2.5 rounded-sm" data-toast-cancel onclick="${o?.onclick}">${o.label}</button>`:"",v=`\n <div\n class="toast"\n role="${"error"===t?"alert":"status"}"\n aria-atomic="true"\n ${t?`data-category="${t}"`:""}\n ${void 0!==s?`data-duration="${s}"`:""}\n >\n <div class="toast-content">\n ${c}\n <section>\n ${l}\n ${u}\n </section>\n ${p||h?`<footer>${p}${h}</footer>`:""}\n </div>\n </div>\n </div>\n `,b=document.createElement("template");return b.innerHTML=v.trim(),b.content.firstChild}(t.detail?.config||{});e.appendChild(a)}));new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches("#toaster")&&r(t),e&&t.matches(".toast:not([data-toast-initialized])")&&i(t))}))}))})).observe(document.body,{childList:!0,subtree:!0})})();
|
|
@@ -5,26 +5,41 @@
|
|
|
5
5
|
const menu = popover.querySelector('[role="menu"]');
|
|
6
6
|
|
|
7
7
|
if (!trigger || !menu || !popover) {
|
|
8
|
-
|
|
8
|
+
const missing = [];
|
|
9
|
+
if (!trigger) missing.push('trigger');
|
|
10
|
+
if (!menu) missing.push('menu');
|
|
11
|
+
if (!popover) missing.push('popover');
|
|
12
|
+
console.error(`Dropdown menu initialisation failed. Missing element(s): ${missing.join(', ')}`, dropdownMenuComponent);
|
|
9
13
|
return;
|
|
10
14
|
}
|
|
11
15
|
|
|
12
16
|
let menuItems = [];
|
|
13
17
|
let activeIndex = -1;
|
|
14
18
|
|
|
15
|
-
const
|
|
19
|
+
const closePopover = (focusOnTrigger = true) => {
|
|
16
20
|
if (trigger.getAttribute('aria-expanded') === 'false') return;
|
|
17
21
|
trigger.setAttribute('aria-expanded', 'false');
|
|
18
22
|
trigger.removeAttribute('aria-activedescendant');
|
|
19
23
|
popover.setAttribute('aria-hidden', 'true');
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
|
|
25
|
+
if (focusOnTrigger) {
|
|
26
|
+
trigger.focus();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
setActiveItem(-1);
|
|
22
30
|
};
|
|
23
31
|
|
|
24
|
-
const
|
|
32
|
+
const openPopover = () => {
|
|
33
|
+
document.dispatchEvent(new CustomEvent('basecoat:popover', {
|
|
34
|
+
detail: { source: dropdownMenuComponent }
|
|
35
|
+
}));
|
|
36
|
+
|
|
25
37
|
trigger.setAttribute('aria-expanded', 'true');
|
|
26
38
|
popover.setAttribute('aria-hidden', 'false');
|
|
27
|
-
menuItems = Array.from(menu.querySelectorAll('[role^="menuitem"]
|
|
39
|
+
menuItems = Array.from(menu.querySelectorAll('[role^="menuitem"]')).filter(item =>
|
|
40
|
+
!item.hasAttribute('disabled') &&
|
|
41
|
+
item.getAttribute('aria-disabled') !== 'true'
|
|
42
|
+
);
|
|
28
43
|
if (menuItems.length > 0) {
|
|
29
44
|
setActiveItem(0);
|
|
30
45
|
}
|
|
@@ -47,24 +62,24 @@
|
|
|
47
62
|
trigger.addEventListener('click', () => {
|
|
48
63
|
const isExpanded = trigger.getAttribute('aria-expanded') === 'true';
|
|
49
64
|
if (isExpanded) {
|
|
50
|
-
|
|
65
|
+
closePopover();
|
|
51
66
|
} else {
|
|
52
|
-
|
|
67
|
+
openPopover();
|
|
53
68
|
}
|
|
54
69
|
});
|
|
55
70
|
|
|
56
|
-
dropdownMenuComponent.addEventListener('keydown', (
|
|
71
|
+
dropdownMenuComponent.addEventListener('keydown', (event) => {
|
|
57
72
|
const isExpanded = trigger.getAttribute('aria-expanded') === 'true';
|
|
58
73
|
|
|
59
|
-
if (
|
|
60
|
-
if (isExpanded)
|
|
74
|
+
if (event.key === 'Escape') {
|
|
75
|
+
if (isExpanded) closePopover();
|
|
61
76
|
return;
|
|
62
77
|
}
|
|
63
78
|
|
|
64
79
|
if (!isExpanded) {
|
|
65
|
-
if (['ArrowDown', 'ArrowUp', 'Enter', ' '].includes(
|
|
66
|
-
|
|
67
|
-
|
|
80
|
+
if (['ArrowDown', 'ArrowUp', 'Enter', ' '].includes(event.key)) {
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
openPopover();
|
|
68
83
|
}
|
|
69
84
|
return;
|
|
70
85
|
}
|
|
@@ -73,28 +88,28 @@
|
|
|
73
88
|
|
|
74
89
|
let nextIndex = activeIndex;
|
|
75
90
|
|
|
76
|
-
switch (
|
|
91
|
+
switch (event.key) {
|
|
77
92
|
case 'ArrowDown':
|
|
78
|
-
|
|
79
|
-
nextIndex = activeIndex
|
|
93
|
+
event.preventDefault();
|
|
94
|
+
nextIndex = Math.min(activeIndex + 1, menuItems.length - 1);
|
|
80
95
|
break;
|
|
81
96
|
case 'ArrowUp':
|
|
82
|
-
|
|
83
|
-
nextIndex = activeIndex
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
nextIndex = Math.max(activeIndex - 1, 0);
|
|
84
99
|
break;
|
|
85
100
|
case 'Home':
|
|
86
|
-
|
|
101
|
+
event.preventDefault();
|
|
87
102
|
nextIndex = 0;
|
|
88
103
|
break;
|
|
89
104
|
case 'End':
|
|
90
|
-
|
|
105
|
+
event.preventDefault();
|
|
91
106
|
nextIndex = menuItems.length - 1;
|
|
92
107
|
break;
|
|
93
108
|
case 'Enter':
|
|
94
109
|
case ' ':
|
|
95
|
-
|
|
110
|
+
event.preventDefault();
|
|
96
111
|
menuItems[activeIndex]?.click();
|
|
97
|
-
|
|
112
|
+
closePopover();
|
|
98
113
|
return;
|
|
99
114
|
}
|
|
100
115
|
|
|
@@ -103,15 +118,21 @@
|
|
|
103
118
|
}
|
|
104
119
|
});
|
|
105
120
|
|
|
106
|
-
menu.addEventListener('click', (
|
|
107
|
-
if (
|
|
108
|
-
|
|
121
|
+
menu.addEventListener('click', (event) => {
|
|
122
|
+
if (event.target.closest('[role^="menuitem"]')) {
|
|
123
|
+
closePopover();
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
document.addEventListener('click', (event) => {
|
|
128
|
+
if (!dropdownMenuComponent.contains(event.target)) {
|
|
129
|
+
closePopover();
|
|
109
130
|
}
|
|
110
131
|
});
|
|
111
132
|
|
|
112
|
-
document.addEventListener('
|
|
113
|
-
if (
|
|
114
|
-
|
|
133
|
+
document.addEventListener('basecoat:popover', (event) => {
|
|
134
|
+
if (event.detail.source !== dropdownMenuComponent) {
|
|
135
|
+
closePopover(false);
|
|
115
136
|
}
|
|
116
137
|
});
|
|
117
138
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{const e=e=>{const t=e.querySelector(":scope > button"),r=e.querySelector(":scope > [data-popover]"),
|
|
1
|
+
(()=>{const e=e=>{const t=e.querySelector(":scope > button"),r=e.querySelector(":scope > [data-popover]"),a=r.querySelector('[role="menu"]');if(!t||!a||!r){const n=[];return t||n.push("trigger"),a||n.push("menu"),r||n.push("popover"),void console.error(`Dropdown menu initialisation failed. Missing element(s): ${n.join(", ")}`,e)}let n=[],i=-1;const o=(e=!0)=>{"false"!==t.getAttribute("aria-expanded")&&(t.setAttribute("aria-expanded","false"),t.removeAttribute("aria-activedescendant"),r.setAttribute("aria-hidden","true"),e&&t.focus(),s(-1))},d=()=>{document.dispatchEvent(new CustomEvent("basecoat:popover",{detail:{source:e}})),t.setAttribute("aria-expanded","true"),r.setAttribute("aria-hidden","false"),n=Array.from(a.querySelectorAll('[role^="menuitem"]')).filter((e=>!e.hasAttribute("disabled")&&"true"!==e.getAttribute("aria-disabled"))),n.length>0&&s(0)},s=e=>{if(i>-1&&n[i]&&n[i].classList.remove("active"),i=e,i>-1&&n[i]){const e=n[i];e.classList.add("active"),t.setAttribute("aria-activedescendant",e.id)}else t.removeAttribute("aria-activedescendant")};t.addEventListener("click",(()=>{"true"===t.getAttribute("aria-expanded")?o():d()})),e.addEventListener("keydown",(e=>{const r="true"===t.getAttribute("aria-expanded");if("Escape"===e.key)return void(r&&o());if(!r)return void(["ArrowDown","ArrowUp","Enter"," "].includes(e.key)&&(e.preventDefault(),d()));if(0===n.length)return;let a=i;switch(e.key){case"ArrowDown":e.preventDefault(),a=Math.min(i+1,n.length-1);break;case"ArrowUp":e.preventDefault(),a=Math.max(i-1,0);break;case"Home":e.preventDefault(),a=0;break;case"End":e.preventDefault(),a=n.length-1;break;case"Enter":case" ":return e.preventDefault(),n[i]?.click(),void o()}a!==i&&s(a)})),a.addEventListener("click",(e=>{e.target.closest('[role^="menuitem"]')&&o()})),document.addEventListener("click",(t=>{e.contains(t.target)||o()})),document.addEventListener("basecoat:popover",(t=>{t.detail.source!==e&&o(!1)})),e.dataset.dropdownMenuInitialized=!0};document.querySelectorAll(".dropdown-menu:not([data-dropdown-menu-initialized])").forEach(e);new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches(".dropdown-menu:not([data-dropdown-menu-initialized])")&&e(t),t.querySelectorAll(".dropdown-menu:not([data-dropdown-menu-initialized])").forEach(e))}))}))})).observe(document.body,{childList:!0,subtree:!0})})();
|
|
@@ -4,18 +4,27 @@
|
|
|
4
4
|
const content = popoverComponent.querySelector(':scope > [data-popover]');
|
|
5
5
|
|
|
6
6
|
if (!trigger || !content) {
|
|
7
|
-
|
|
7
|
+
const missing = [];
|
|
8
|
+
if (!trigger) missing.push('trigger');
|
|
9
|
+
if (!content) missing.push('content');
|
|
10
|
+
console.error(`Popover initialisation failed. Missing element(s): ${missing.join(', ')}`, popoverComponent);
|
|
8
11
|
return;
|
|
9
12
|
}
|
|
10
13
|
|
|
11
|
-
const closePopover = () => {
|
|
14
|
+
const closePopover = (focusOnTrigger = true) => {
|
|
12
15
|
if (trigger.getAttribute('aria-expanded') === 'false') return;
|
|
13
16
|
trigger.setAttribute('aria-expanded', 'false');
|
|
14
17
|
content.setAttribute('aria-hidden', 'true');
|
|
15
|
-
|
|
18
|
+
if (focusOnTrigger) {
|
|
19
|
+
trigger.focus();
|
|
20
|
+
}
|
|
16
21
|
};
|
|
17
22
|
|
|
18
23
|
const openPopover = () => {
|
|
24
|
+
document.dispatchEvent(new CustomEvent('basecoat:popover', {
|
|
25
|
+
detail: { source: popoverComponent }
|
|
26
|
+
}));
|
|
27
|
+
|
|
19
28
|
const elementToFocus = content.querySelector('[autofocus]');
|
|
20
29
|
if (elementToFocus) {
|
|
21
30
|
content.addEventListener('transitionend', () => {
|
|
@@ -36,18 +45,24 @@
|
|
|
36
45
|
}
|
|
37
46
|
});
|
|
38
47
|
|
|
39
|
-
popoverComponent.addEventListener('keydown', (
|
|
40
|
-
if (
|
|
48
|
+
popoverComponent.addEventListener('keydown', (event) => {
|
|
49
|
+
if (event.key === 'Escape') {
|
|
41
50
|
closePopover();
|
|
42
51
|
}
|
|
43
52
|
});
|
|
44
53
|
|
|
45
|
-
document.addEventListener('click', (
|
|
46
|
-
if (!popoverComponent.contains(
|
|
54
|
+
document.addEventListener('click', (event) => {
|
|
55
|
+
if (!popoverComponent.contains(event.target)) {
|
|
47
56
|
closePopover();
|
|
48
57
|
}
|
|
49
58
|
});
|
|
50
59
|
|
|
60
|
+
document.addEventListener('basecoat:popover', (event) => {
|
|
61
|
+
if (event.detail.source !== popoverComponent) {
|
|
62
|
+
closePopover(false);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
51
66
|
popoverComponent.dataset.popoverInitialized = true;
|
|
52
67
|
};
|
|
53
68
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{const e=e=>{const t=e.querySelector(":scope > button"),o=e.querySelector(":scope > [data-popover]");if(!t||!o)return void console.error(
|
|
1
|
+
(()=>{const e=e=>{const t=e.querySelector(":scope > button"),o=e.querySelector(":scope > [data-popover]");if(!t||!o){const a=[];return t||a.push("trigger"),o||a.push("content"),void console.error(`Popover initialisation failed. Missing element(s): ${a.join(", ")}`,e)}const a=(e=!0)=>{"false"!==t.getAttribute("aria-expanded")&&(t.setAttribute("aria-expanded","false"),o.setAttribute("aria-hidden","true"),e&&t.focus())};t.addEventListener("click",(()=>{"true"===t.getAttribute("aria-expanded")?a():(()=>{document.dispatchEvent(new CustomEvent("basecoat:popover",{detail:{source:e}}));const a=o.querySelector("[autofocus]");a&&o.addEventListener("transitionend",(()=>{a.focus()}),{once:!0}),t.setAttribute("aria-expanded","true"),o.setAttribute("aria-hidden","false")})()})),e.addEventListener("keydown",(e=>{"Escape"===e.key&&a()})),document.addEventListener("click",(t=>{e.contains(t.target)||a()})),document.addEventListener("basecoat:popover",(t=>{t.detail.source!==e&&a(!1)})),e.dataset.popoverInitialized=!0};document.querySelectorAll(".popover:not([data-popover-initialized])").forEach(e);new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches(".popover:not([data-popover-initialized])")&&e(t),t.querySelectorAll(".popover:not([data-popover-initialized])").forEach(e))}))}))})).observe(document.body,{childList:!0,subtree:!0})})();
|
package/dist/assets/js/select.js
CHANGED
|
@@ -6,12 +6,25 @@
|
|
|
6
6
|
const listbox = popover.querySelector('[role="listbox"]');
|
|
7
7
|
const input = selectComponent.querySelector(':scope > input[type="hidden"]');
|
|
8
8
|
const filter = selectComponent.querySelector('header input[type="text"]');
|
|
9
|
-
if (!trigger || !popover || !listbox || !input)
|
|
9
|
+
if (!trigger || !popover || !listbox || !input) {
|
|
10
|
+
const missing = [];
|
|
11
|
+
if (!trigger) missing.push('trigger');
|
|
12
|
+
if (!popover) missing.push('popover');
|
|
13
|
+
if (!listbox) missing.push('listbox');
|
|
14
|
+
if (!input) missing.push('input');
|
|
15
|
+
console.error(`Select component initialisation failed. Missing element(s): ${missing.join(', ')}`, selectComponent);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
10
18
|
|
|
11
19
|
const options = Array.from(listbox.querySelectorAll('[role="option"]'));
|
|
12
20
|
let visibleOptions = [...options];
|
|
13
21
|
let activeIndex = -1;
|
|
14
22
|
|
|
23
|
+
const hasTransition = () => {
|
|
24
|
+
const style = getComputedStyle(popover);
|
|
25
|
+
return parseFloat(style.transitionDuration) > 0 || parseFloat(style.transitionDelay) > 0;
|
|
26
|
+
};
|
|
27
|
+
|
|
15
28
|
const updateValue = (option) => {
|
|
16
29
|
if (option) {
|
|
17
30
|
selectedValue.innerHTML = option.dataset.label || option.innerHTML;
|
|
@@ -21,14 +34,26 @@
|
|
|
21
34
|
}
|
|
22
35
|
};
|
|
23
36
|
|
|
24
|
-
const closePopover = () => {
|
|
25
|
-
popover.
|
|
26
|
-
|
|
37
|
+
const closePopover = (focusOnTrigger = true) => {
|
|
38
|
+
if (popover.getAttribute('aria-hidden') === 'true') return;
|
|
39
|
+
|
|
27
40
|
if (filter) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
41
|
+
const resetFilter = () => {
|
|
42
|
+
filter.value = '';
|
|
43
|
+
visibleOptions = [...options];
|
|
44
|
+
options.forEach(opt => opt.setAttribute('aria-hidden', 'false'));
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
if (hasTransition()) {
|
|
48
|
+
popover.addEventListener('transitionend', resetFilter, { once: true });
|
|
49
|
+
} else {
|
|
50
|
+
resetFilter();
|
|
51
|
+
}
|
|
31
52
|
}
|
|
53
|
+
|
|
54
|
+
if (focusOnTrigger) trigger.focus();
|
|
55
|
+
popover.setAttribute('aria-hidden', 'true');
|
|
56
|
+
trigger.setAttribute('aria-expanded', 'false');
|
|
32
57
|
trigger.removeAttribute('aria-activedescendant');
|
|
33
58
|
if (activeIndex > -1) options[activeIndex]?.classList.remove('active');
|
|
34
59
|
activeIndex = -1;
|
|
@@ -37,10 +62,17 @@
|
|
|
37
62
|
const selectOption = (option) => {
|
|
38
63
|
if (!option) return;
|
|
39
64
|
|
|
40
|
-
if (option.dataset.value) {
|
|
65
|
+
if (option.dataset.value != null) {
|
|
41
66
|
updateValue(option);
|
|
42
67
|
}
|
|
68
|
+
|
|
43
69
|
closePopover();
|
|
70
|
+
|
|
71
|
+
const event = new CustomEvent('change', {
|
|
72
|
+
detail: { value: option.dataset.value },
|
|
73
|
+
bubbles: true
|
|
74
|
+
});
|
|
75
|
+
selectComponent.dispatchEvent(event);
|
|
44
76
|
};
|
|
45
77
|
|
|
46
78
|
if (filter) {
|
|
@@ -67,36 +99,36 @@
|
|
|
67
99
|
filter.addEventListener('input', filterOptions);
|
|
68
100
|
}
|
|
69
101
|
|
|
70
|
-
let initialOption = options.find(opt =>
|
|
102
|
+
let initialOption = options.find(opt => opt.dataset.value === input.value);
|
|
71
103
|
if (!initialOption && options.length > 0) initialOption = options[0];
|
|
72
104
|
|
|
73
105
|
updateValue(initialOption);
|
|
74
106
|
|
|
75
|
-
const handleKeyNavigation = (
|
|
107
|
+
const handleKeyNavigation = (event) => {
|
|
76
108
|
const isPopoverOpen = popover.getAttribute('aria-hidden') === 'false';
|
|
77
109
|
|
|
78
|
-
if (!['ArrowDown', 'ArrowUp', 'Enter', 'Home', 'End', 'Escape'].includes(
|
|
110
|
+
if (!['ArrowDown', 'ArrowUp', 'Enter', 'Home', 'End', 'Escape'].includes(event.key)) {
|
|
79
111
|
return;
|
|
80
112
|
}
|
|
81
113
|
|
|
82
114
|
if (!isPopoverOpen) {
|
|
83
|
-
if (
|
|
84
|
-
|
|
115
|
+
if (event.key !== 'Enter' && event.key !== 'Escape') {
|
|
116
|
+
event.preventDefault();
|
|
85
117
|
trigger.click();
|
|
86
118
|
}
|
|
87
119
|
return;
|
|
88
120
|
}
|
|
89
121
|
|
|
90
|
-
|
|
122
|
+
event.preventDefault();
|
|
91
123
|
|
|
92
|
-
if (
|
|
124
|
+
if (event.key === 'Escape') {
|
|
93
125
|
closePopover();
|
|
94
126
|
return;
|
|
95
127
|
}
|
|
96
128
|
|
|
97
|
-
if (
|
|
129
|
+
if (event.key === 'Enter') {
|
|
98
130
|
if (activeIndex > -1) {
|
|
99
|
-
selectOption(
|
|
131
|
+
selectOption(options[activeIndex]);
|
|
100
132
|
}
|
|
101
133
|
return;
|
|
102
134
|
}
|
|
@@ -106,7 +138,7 @@
|
|
|
106
138
|
const currentVisibleIndex = activeIndex > -1 ? visibleOptions.indexOf(options[activeIndex]) : -1;
|
|
107
139
|
let nextVisibleIndex = currentVisibleIndex;
|
|
108
140
|
|
|
109
|
-
switch (
|
|
141
|
+
switch (event.key) {
|
|
110
142
|
case 'ArrowDown':
|
|
111
143
|
if (currentVisibleIndex < visibleOptions.length - 1) {
|
|
112
144
|
nextVisibleIndex = currentVisibleIndex + 1;
|
|
@@ -116,7 +148,7 @@
|
|
|
116
148
|
if (currentVisibleIndex > 0) {
|
|
117
149
|
nextVisibleIndex = currentVisibleIndex - 1;
|
|
118
150
|
} else if (currentVisibleIndex === -1) {
|
|
119
|
-
nextVisibleIndex = 0;
|
|
151
|
+
nextVisibleIndex = 0;
|
|
120
152
|
}
|
|
121
153
|
break;
|
|
122
154
|
case 'Home':
|
|
@@ -148,41 +180,63 @@
|
|
|
148
180
|
filter.addEventListener('keydown', handleKeyNavigation);
|
|
149
181
|
}
|
|
150
182
|
|
|
183
|
+
const openPopover = () => {
|
|
184
|
+
document.dispatchEvent(new CustomEvent('basecoat:popover', {
|
|
185
|
+
detail: { source: selectComponent }
|
|
186
|
+
}));
|
|
187
|
+
|
|
188
|
+
if (filter) {
|
|
189
|
+
if (hasTransition()) {
|
|
190
|
+
popover.addEventListener('transitionend', () => {
|
|
191
|
+
filter.focus();
|
|
192
|
+
}, { once: true });
|
|
193
|
+
} else {
|
|
194
|
+
filter.focus();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
popover.setAttribute('aria-hidden', 'false');
|
|
199
|
+
trigger.setAttribute('aria-expanded', 'true');
|
|
200
|
+
|
|
201
|
+
const selectedOption = listbox.querySelector('[role="option"][aria-selected="true"]');
|
|
202
|
+
if (selectedOption) {
|
|
203
|
+
if (activeIndex > -1) {
|
|
204
|
+
options[activeIndex]?.classList.remove('active');
|
|
205
|
+
}
|
|
206
|
+
activeIndex = options.indexOf(selectedOption);
|
|
207
|
+
selectedOption.classList.add('active');
|
|
208
|
+
if (selectedOption.id) {
|
|
209
|
+
trigger.setAttribute('aria-activedescendant', selectedOption.id);
|
|
210
|
+
}
|
|
211
|
+
selectedOption.scrollIntoView({ block: 'nearest' });
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
|
|
151
215
|
trigger.addEventListener('click', () => {
|
|
152
216
|
const isExpanded = trigger.getAttribute('aria-expanded') === 'true';
|
|
153
|
-
|
|
154
217
|
if (isExpanded) {
|
|
155
218
|
closePopover();
|
|
156
219
|
} else {
|
|
157
|
-
|
|
158
|
-
trigger.setAttribute('aria-expanded', 'true');
|
|
159
|
-
if (filter) filter.focus();
|
|
160
|
-
|
|
161
|
-
const selectedOption = listbox.querySelector('[role="option"][aria-selected="true"]');
|
|
162
|
-
if (selectedOption) {
|
|
163
|
-
if (activeIndex > -1) {
|
|
164
|
-
options[activeIndex]?.classList.remove('active');
|
|
165
|
-
}
|
|
166
|
-
activeIndex = options.indexOf(selectedOption);
|
|
167
|
-
selectedOption.classList.add('active');
|
|
168
|
-
if (selectedOption.id) {
|
|
169
|
-
trigger.setAttribute('aria-activedescendant', selectedOption.id);
|
|
170
|
-
}
|
|
171
|
-
selectedOption.scrollIntoView({ block: 'nearest' });
|
|
172
|
-
}
|
|
220
|
+
openPopover();
|
|
173
221
|
}
|
|
174
222
|
});
|
|
175
223
|
|
|
176
|
-
listbox.addEventListener('click', (
|
|
177
|
-
const clickedOption =
|
|
224
|
+
listbox.addEventListener('click', (event) => {
|
|
225
|
+
const clickedOption = event.target.closest('[role="option"]');
|
|
178
226
|
if (clickedOption) {
|
|
179
227
|
selectOption(clickedOption);
|
|
180
228
|
}
|
|
181
229
|
});
|
|
182
230
|
|
|
183
|
-
document.addEventListener('click', (
|
|
184
|
-
if (!selectComponent.contains(
|
|
185
|
-
closePopover();
|
|
231
|
+
document.addEventListener('click', (event) => {
|
|
232
|
+
if (!selectComponent.contains(event.target)) {
|
|
233
|
+
closePopover(false);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
document.addEventListener('basecoat:popover', (event) => {
|
|
238
|
+
if (event.detail.source !== selectComponent) {
|
|
239
|
+
closePopover(false);
|
|
186
240
|
}
|
|
187
241
|
});
|
|
188
242
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{const e=e=>{const t=e.querySelector(":scope > button"),
|
|
1
|
+
(()=>{const e=e=>{const t=e.querySelector(":scope > button"),a=t.querySelector(":scope > span"),r=e.querySelector(":scope > [data-popover]"),i=r.querySelector('[role="listbox"]'),n=e.querySelector(':scope > input[type="hidden"]'),s=e.querySelector('header input[type="text"]');if(!(t&&r&&i&&n)){const a=[];return t||a.push("trigger"),r||a.push("popover"),i||a.push("listbox"),n||a.push("input"),void console.error(`Select component initialisation failed. Missing element(s): ${a.join(", ")}`,e)}const o=Array.from(i.querySelectorAll('[role="option"]'));let c=[...o],d=-1;const l=()=>{const e=getComputedStyle(r);return parseFloat(e.transitionDuration)>0||parseFloat(e.transitionDelay)>0},u=e=>{e&&(a.innerHTML=e.dataset.label||e.innerHTML,n.value=e.dataset.value,i.querySelector('[role="option"][aria-selected="true"]')?.removeAttribute("aria-selected"),e.setAttribute("aria-selected","true"))},v=(e=!0)=>{if("true"!==r.getAttribute("aria-hidden")){if(s){const e=()=>{s.value="",c=[...o],o.forEach((e=>e.setAttribute("aria-hidden","false")))};l()?r.addEventListener("transitionend",e,{once:!0}):e()}e&&t.focus(),r.setAttribute("aria-hidden","true"),t.setAttribute("aria-expanded","false"),t.removeAttribute("aria-activedescendant"),d>-1&&o[d]?.classList.remove("active"),d=-1}},p=t=>{if(!t)return;null!=t.dataset.value&&u(t),v();const a=new CustomEvent("change",{detail:{value:t.dataset.value},bubbles:!0});e.dispatchEvent(a)};if(s){const e=()=>{const e=s.value.trim().toLowerCase();d>-1&&(o[d].classList.remove("active"),t.removeAttribute("aria-activedescendant"),d=-1),c=[],o.forEach((t=>{const a=(t.dataset.label||t.textContent).trim().toLowerCase().includes(e);t.setAttribute("aria-hidden",String(!a)),a&&c.push(t)}))};s.addEventListener("input",e)}let b=o.find((e=>e.dataset.value===n.value));!b&&o.length>0&&(b=o[0]),u(b);const f=e=>{const a="false"===r.getAttribute("aria-hidden");if(!["ArrowDown","ArrowUp","Enter","Home","End","Escape"].includes(e.key))return;if(!a)return void("Enter"!==e.key&&"Escape"!==e.key&&(e.preventDefault(),t.click()));if(e.preventDefault(),"Escape"===e.key)return void v();if("Enter"===e.key)return void(d>-1&&p(o[d]));if(0===c.length)return;const i=d>-1?c.indexOf(o[d]):-1;let n=i;switch(e.key){case"ArrowDown":i<c.length-1&&(n=i+1);break;case"ArrowUp":i>0?n=i-1:-1===i&&(n=0);break;case"Home":n=0;break;case"End":n=c.length-1}if(n!==i){i>-1&&c[i].classList.remove("active");const e=c[n];e.classList.add("active"),d=o.indexOf(e),e.id&&t.setAttribute("aria-activedescendant",e.id),e.scrollIntoView({block:"nearest",behavior:"smooth"})}};t.addEventListener("keydown",f),s&&s.addEventListener("keydown",f);t.addEventListener("click",(()=>{"true"===t.getAttribute("aria-expanded")?v():(()=>{document.dispatchEvent(new CustomEvent("basecoat:popover",{detail:{source:e}})),s&&(l()?r.addEventListener("transitionend",(()=>{s.focus()}),{once:!0}):s.focus()),r.setAttribute("aria-hidden","false"),t.setAttribute("aria-expanded","true");const a=i.querySelector('[role="option"][aria-selected="true"]');a&&(d>-1&&o[d]?.classList.remove("active"),d=o.indexOf(a),a.classList.add("active"),a.id&&t.setAttribute("aria-activedescendant",a.id),a.scrollIntoView({block:"nearest"}))})()})),i.addEventListener("click",(e=>{const t=e.target.closest('[role="option"]');t&&p(t)})),document.addEventListener("click",(t=>{e.contains(t.target)||v(!1)})),document.addEventListener("basecoat:popover",(t=>{t.detail.source!==e&&v(!1)})),r.setAttribute("aria-hidden","true"),e.dataset.selectInitialized=!0};document.querySelectorAll("div.select:not([data-select-initialized])").forEach(e);new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches("div.select:not([data-select-initialized])")&&e(t),t.querySelectorAll("div.select:not([data-select-initialized])").forEach(e))}))}))})).observe(document.body,{childList:!0,subtree:!0})})();
|
|
@@ -55,18 +55,24 @@
|
|
|
55
55
|
|
|
56
56
|
const sidebarId = sidebarComponent.id;
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
document.addEventListener('basecoat:sidebar', (event) => {
|
|
59
|
+
if (event.detail?.id && event.detail.id !== sidebarId) return;
|
|
60
|
+
|
|
61
|
+
switch (event.detail?.action) {
|
|
62
|
+
case 'open':
|
|
63
|
+
setState(true);
|
|
64
|
+
break;
|
|
65
|
+
case 'close':
|
|
66
|
+
setState(false);
|
|
67
|
+
break;
|
|
68
|
+
default:
|
|
69
|
+
setState(!open);
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
66
72
|
});
|
|
67
73
|
|
|
68
|
-
sidebarComponent.addEventListener('click', (
|
|
69
|
-
const target =
|
|
74
|
+
sidebarComponent.addEventListener('click', (event) => {
|
|
75
|
+
const target = event.target;
|
|
70
76
|
const nav = sidebarComponent.querySelector('nav');
|
|
71
77
|
|
|
72
78
|
const isMobile = window.innerWidth < breakpoint;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{if(!window.history.__basecoatPatched){const e=window.history.pushState;window.history.pushState=function(...t){e.apply(this,t),window.dispatchEvent(new Event("basecoat:locationchange"))};const t=window.history.replaceState;window.history.replaceState=function(...e){t.apply(this,e),window.dispatchEvent(new Event("basecoat:locationchange"))},window.history.__basecoatPatched=!0}const e=e=>{const t="false"!==e.dataset.initialOpen,
|
|
1
|
+
(()=>{if(!window.history.__basecoatPatched){const e=window.history.pushState;window.history.pushState=function(...t){e.apply(this,t),window.dispatchEvent(new Event("basecoat:locationchange"))};const t=window.history.replaceState;window.history.replaceState=function(...e){t.apply(this,e),window.dispatchEvent(new Event("basecoat:locationchange"))},window.history.__basecoatPatched=!0}const e=e=>{const t="false"!==e.dataset.initialOpen,a="true"===e.dataset.initialMobileOpen,i=parseInt(e.dataset.breakpoint)||768;let n=i>0?window.innerWidth>=i?t:a:t;const o=()=>{const t=window.location.pathname.replace(/\/$/,"");e.querySelectorAll("a").forEach((e=>{if(e.hasAttribute("data-ignore-current"))return;new URL(e.href).pathname.replace(/\/$/,"")===t?e.setAttribute("aria-current","page"):e.removeAttribute("aria-current")}))},r=()=>{e.setAttribute("aria-hidden",!n),n?e.removeAttribute("inert"):e.setAttribute("inert","")},d=e=>{n=e,r()},c=e.id;document.addEventListener("basecoat:sidebar",(e=>{if(!e.detail?.id||e.detail.id===c)switch(e.detail?.action){case"open":d(!0);break;case"close":d(!1);break;default:d(!n)}})),e.addEventListener("click",(t=>{const a=t.target,n=e.querySelector("nav");if(window.innerWidth<i&&a.closest("a, button")&&!a.closest("[data-keep-mobile-sidebar-open]"))return document.activeElement&&document.activeElement.blur(),void d(!1);(a===e||n&&!n.contains(a))&&(document.activeElement&&document.activeElement.blur(),d(!1))})),window.addEventListener("popstate",o),window.addEventListener("basecoat:locationchange",o),r(),o(),e.dataset.sidebarInitialized=!0};document.querySelectorAll(".sidebar:not([data-sidebar-initialized])").forEach(e);new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches(".sidebar:not([data-sidebar-initialized])")&&e(t),t.querySelectorAll(".sidebar:not([data-sidebar-initialized])").forEach(e))}))}))})).observe(document.body,{childList:!0,subtree:!0})})();
|