basecoat-cli 0.3.9 → 0.3.10-beta.2
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/carousel.html.jinja +111 -0
- package/dist/assets/jinja/select.html.jinja +35 -15
- package/dist/assets/js/all.js +185 -50
- package/dist/assets/js/all.min.js +1 -1
- package/dist/assets/js/carousel.js +192 -0
- package/dist/assets/js/carousel.min.js +1 -0
- package/dist/assets/js/select.js +185 -50
- package/dist/assets/js/select.min.js +1 -1
- package/dist/assets/nunjucks/carousel.njk +111 -0
- package/dist/assets/nunjucks/select.njk +36 -16
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{const e={};let t=null;const n=()=>{Object.entries(e).forEach((([e,{selector:t,init:n}])=>{document.querySelectorAll(t).forEach(n)}))},i=t=>{t.nodeType===Node.ELEMENT_NODE&&Object.entries(e).forEach((([e,{selector:n,init:i}])=>{t.matches(n)&&i(t),t.querySelectorAll(n).forEach(i)}))},a=()=>{t||(t=new MutationObserver((e=>{e.forEach((e=>{e.addedNodes.forEach(i)}))})),t.observe(document.body,{childList:!0,subtree:!0}))};window.basecoat={register:(t,n,i)=>{e[t]={selector:n,init:i}},init:t=>{const n=e[t];if(!n)return void console.warn(`Component '${t}' not found in registry`);const i=`data-${t}-initialized`;document.querySelectorAll(`[${i}]`).forEach((e=>{e.removeAttribute(i)})),document.querySelectorAll(n.selector).forEach(n.init)},initAll:()=>{Object.entries(e).forEach((([e,{selector:t}])=>{const n=`data-${e}-initialized`;document.querySelectorAll(`[${n}]`).forEach((e=>{e.removeAttribute(n)}))})),n()},start:a,stop:()=>{t&&(t.disconnect(),t=null)}},document.addEventListener("DOMContentLoaded",(()=>{n(),a()}))})(),(()=>{const e=e=>{const t=e.querySelector("header input"),n=e.querySelector('[role="menu"]');if(!t||!n){const i=[];return t||i.push("input"),n||i.push("menu"),void console.error(`Command component initialization failed. Missing element(s): ${i.join(", ")}`,e)}const i=Array.from(n.querySelectorAll('[role="menuitem"]')),a=i.filter((e=>!e.hasAttribute("disabled")&&"true"!==e.getAttribute("aria-disabled")));let o=[...a],r=-1;const s=e=>{if(r>-1&&a[r]&&a[r].classList.remove("active"),r=e,r>-1){const e=a[r];e.classList.add("active"),e.id?t.setAttribute("aria-activedescendant",e.id):t.removeAttribute("aria-activedescendant")}else t.removeAttribute("aria-activedescendant")};t.addEventListener("input",(()=>{const e=t.value.trim().toLowerCase();s(-1),o=[],i.forEach((t=>{if(t.hasAttribute("data-force"))return t.setAttribute("aria-hidden","false"),void(a.includes(t)&&o.push(t));const n=(t.dataset.filter||t.textContent).trim().toLowerCase(),i=(t.dataset.keywords||"").toLowerCase().split(/[\s,]+/).filter(Boolean).some((t=>t.includes(e))),r=n.includes(e)||i;t.setAttribute("aria-hidden",String(!r)),r&&a.includes(t)&&o.push(t)})),o.length>0&&(s(a.indexOf(o[0])),o[0].scrollIntoView({block:"nearest"}))}));n.addEventListener("mousemove",(e=>{const t=e.target.closest('[role="menuitem"]');if(t&&o.includes(t)){const e=a.indexOf(t);e!==r&&s(e)}})),n.addEventListener("click",(t=>{const n=t.target.closest('[role="menuitem"]');if(n&&o.includes(n)){const t=e.closest("dialog.command-dialog");t&&!n.hasAttribute("data-keep-command-open")&&t.close()}})),t.addEventListener("keydown",(e=>{if(!["ArrowDown","ArrowUp","Enter","Home","End"].includes(e.key))return;if("Enter"===e.key)return e.preventDefault(),void(r>-1&&a[r]?.click());if(0===o.length)return;e.preventDefault();const t=r>-1?o.indexOf(a[r]):-1;let n=t;switch(e.key){case"ArrowDown":t<o.length-1&&(n=t+1);break;case"ArrowUp":t>0?n=t-1:-1===t&&(n=0);break;case"Home":n=0;break;case"End":n=o.length-1}if(n!==t){const e=o[n];s(a.indexOf(e)),e.scrollIntoView({block:"nearest",behavior:"smooth"})}})),o.length>0&&(s(a.indexOf(o[0])),o[0].scrollIntoView({block:"nearest"})),e.dataset.commandInitialized=!0,e.dispatchEvent(new CustomEvent("basecoat:initialized"))};window.basecoat&&window.basecoat.register("command",".command:not([data-command-initialized])",e)})(),(()=>{const e=e=>{const t=e.querySelector(":scope > button"),n=e.querySelector(":scope > [data-popover]"),i=n.querySelector('[role="menu"]');if(!t||!i||!n){const a=[];return t||a.push("trigger"),i||a.push("menu"),n||a.push("popover"),void console.error(`Dropdown menu initialisation failed. Missing element(s): ${a.join(", ")}`,e)}let a=[],o=-1;const r=(e=!0)=>{"false"!==t.getAttribute("aria-expanded")&&(t.setAttribute("aria-expanded","false"),t.removeAttribute("aria-activedescendant"),n.setAttribute("aria-hidden","true"),e&&t.focus(),d(-1))},s=(o=!1)=>{document.dispatchEvent(new CustomEvent("basecoat:popover",{detail:{source:e}})),t.setAttribute("aria-expanded","true"),n.setAttribute("aria-hidden","false"),a=Array.from(i.querySelectorAll('[role^="menuitem"]')).filter((e=>!e.hasAttribute("disabled")&&"true"!==e.getAttribute("aria-disabled"))),a.length>0&&o&&("first"===o?d(0):"last"===o&&d(a.length-1))},d=e=>{if(o>-1&&a[o]&&a[o].classList.remove("active"),o=e,o>-1&&a[o]){const e=a[o];e.classList.add("active"),t.setAttribute("aria-activedescendant",e.id)}else t.removeAttribute("aria-activedescendant")};t.addEventListener("click",(()=>{"true"===t.getAttribute("aria-expanded")?r():s(!1)})),e.addEventListener("keydown",(e=>{const n="true"===t.getAttribute("aria-expanded");if("Escape"===e.key)return void(n&&r());if(!n)return void(["Enter"," "].includes(e.key)?(e.preventDefault(),s(!1)):"ArrowDown"===e.key?(e.preventDefault(),s("first")):"ArrowUp"===e.key&&(e.preventDefault(),s("last")));if(0===a.length)return;let i=o;switch(e.key){case"ArrowDown":e.preventDefault(),i=-1===o?0:Math.min(o+1,a.length-1);break;case"ArrowUp":e.preventDefault(),i=-1===o?a.length-1:Math.max(o-1,0);break;case"Home":e.preventDefault(),i=0;break;case"End":e.preventDefault(),i=a.length-1;break;case"Enter":case" ":return e.preventDefault(),a[o]?.click(),void r()}i!==o&&d(i)})),i.addEventListener("mousemove",(e=>{const t=e.target.closest('[role^="menuitem"]');if(t&&a.includes(t)){const e=a.indexOf(t);e!==o&&d(e)}})),i.addEventListener("mouseleave",(()=>{d(-1)})),i.addEventListener("click",(e=>{e.target.closest('[role^="menuitem"]')&&r()})),document.addEventListener("click",(t=>{e.contains(t.target)||r()})),document.addEventListener("basecoat:popover",(t=>{t.detail.source!==e&&r(!1)})),e.dataset.dropdownMenuInitialized=!0,e.dispatchEvent(new CustomEvent("basecoat:initialized"))};window.basecoat&&window.basecoat.register("dropdown-menu",".dropdown-menu:not([data-dropdown-menu-initialized])",e)})(),(()=>{const e=e=>{const t=e.querySelector(":scope > button"),n=e.querySelector(":scope > [data-popover]");if(!t||!n){const i=[];return t||i.push("trigger"),n||i.push("content"),void console.error(`Popover initialisation failed. Missing element(s): ${i.join(", ")}`,e)}const i=(e=!0)=>{"false"!==t.getAttribute("aria-expanded")&&(t.setAttribute("aria-expanded","false"),n.setAttribute("aria-hidden","true"),e&&t.focus())};t.addEventListener("click",(()=>{"true"===t.getAttribute("aria-expanded")?i():(()=>{document.dispatchEvent(new CustomEvent("basecoat:popover",{detail:{source:e}}));const i=n.querySelector("[autofocus]");i&&n.addEventListener("transitionend",(()=>{i.focus()}),{once:!0}),t.setAttribute("aria-expanded","true"),n.setAttribute("aria-hidden","false")})()})),e.addEventListener("keydown",(e=>{"Escape"===e.key&&i()})),document.addEventListener("click",(t=>{e.contains(t.target)||i()})),document.addEventListener("basecoat:popover",(t=>{t.detail.source!==e&&i(!1)})),e.dataset.popoverInitialized=!0,e.dispatchEvent(new CustomEvent("basecoat:initialized"))};window.basecoat&&window.basecoat.register("popover",".popover:not([data-popover-initialized])",e)})(),(()=>{const e=e=>{const t=e.querySelector(":scope > button"),n=t.querySelector(":scope > span"),i=e.querySelector(":scope > [data-popover]"),a=i.querySelector('[role="listbox"]'),o=e.querySelector(':scope > input[type="hidden"]'),r=e.querySelector('header input[type="text"]');if(!(t&&i&&a&&o)){const n=[];return t||n.push("trigger"),i||n.push("popover"),a||n.push("listbox"),o||n.push("input"),void console.error(`Select component initialisation failed. Missing element(s): ${n.join(", ")}`,e)}const s=Array.from(a.querySelectorAll('[role="option"]')),d=s.filter((e=>"true"!==e.getAttribute("aria-disabled")));let c=[...d],l=-1;const u=e=>{if(l>-1&&d[l]&&d[l].classList.remove("active"),l=e,l>-1){const e=d[l];e.classList.add("active"),e.id?t.setAttribute("aria-activedescendant",e.id):t.removeAttribute("aria-activedescendant")}else t.removeAttribute("aria-activedescendant")},v=()=>{const e=getComputedStyle(i);return parseFloat(e.transitionDuration)>0||parseFloat(e.transitionDelay)>0},p=(t,i=!0)=>{if(t&&(n.innerHTML=t.innerHTML,o.value=t.dataset.value,a.querySelector('[role="option"][aria-selected="true"]')?.removeAttribute("aria-selected"),t.setAttribute("aria-selected","true"),i)){const n=new CustomEvent("change",{detail:{value:t.dataset.value},bubbles:!0});e.dispatchEvent(n)}},m=(e=!0)=>{if("true"!==i.getAttribute("aria-hidden")){if(r){const e=()=>{r.value="",c=[...d],s.forEach((e=>e.setAttribute("aria-hidden","false")))};v()?i.addEventListener("transitionend",e,{once:!0}):e()}e&&t.focus(),i.setAttribute("aria-hidden","true"),t.setAttribute("aria-expanded","false"),u(-1)}},b=e=>{if(!e)return;const t=o.value,n=e.dataset.value;null!=n&&n!==t&&p(e),m()};if(r){const e=()=>{const e=r.value.trim().toLowerCase();u(-1),c=[],s.forEach((t=>{if(t.hasAttribute("data-force"))return t.setAttribute("aria-hidden","false"),void(d.includes(t)&&c.push(t));const n=(t.dataset.filter||t.textContent).trim().toLowerCase(),i=(t.dataset.keywords||"").toLowerCase().split(/[\s,]+/).filter(Boolean).some((t=>t.includes(e))),a=n.includes(e)||i;t.setAttribute("aria-hidden",String(!a)),a&&d.includes(t)&&c.push(t)}))};r.addEventListener("input",e)}let h=d.find((e=>e.dataset.value===o.value));h||(h=d.find((e=>void 0!==e.dataset.value))??d[0]),p(h,!1);const f=e=>{const n="false"===i.getAttribute("aria-hidden");if(!["ArrowDown","ArrowUp","Enter","Home","End","Escape"].includes(e.key))return;if(!n)return void("Enter"!==e.key&&"Escape"!==e.key&&(e.preventDefault(),t.click()));if(e.preventDefault(),"Escape"===e.key)return void m();if("Enter"===e.key)return void(l>-1&&b(d[l]));if(0===c.length)return;const a=l>-1?c.indexOf(d[l]):-1;let o=a;switch(e.key){case"ArrowDown":a<c.length-1&&(o=a+1);break;case"ArrowUp":a>0?o=a-1:-1===a&&(o=0);break;case"Home":o=0;break;case"End":o=c.length-1}if(o!==a){const e=c[o];u(d.indexOf(e)),e.scrollIntoView({block:"nearest",behavior:"smooth"})}};a.addEventListener("mousemove",(e=>{const t=e.target.closest('[role="option"]');if(t&&c.includes(t)){const e=d.indexOf(t);e!==l&&u(e)}})),a.addEventListener("mouseleave",(()=>{const e=a.querySelector('[role="option"][aria-selected="true"]');u(e?d.indexOf(e):-1)})),t.addEventListener("keydown",f),r&&r.addEventListener("keydown",f);t.addEventListener("click",(()=>{"true"===t.getAttribute("aria-expanded")?m():(()=>{document.dispatchEvent(new CustomEvent("basecoat:popover",{detail:{source:e}})),r&&(v()?i.addEventListener("transitionend",(()=>{r.focus()}),{once:!0}):r.focus()),i.setAttribute("aria-hidden","false"),t.setAttribute("aria-expanded","true");const n=a.querySelector('[role="option"][aria-selected="true"]');n&&(u(d.indexOf(n)),n.scrollIntoView({block:"nearest"}))})()})),a.addEventListener("click",(e=>{const t=e.target.closest('[role="option"]');t&&b(t)})),document.addEventListener("click",(t=>{e.contains(t.target)||m(!1)})),document.addEventListener("basecoat:popover",(t=>{t.detail.source!==e&&m(!1)})),i.setAttribute("aria-hidden","true"),e.selectByValue=e=>{const t=d.find((t=>t.dataset.value===e));b(t)},e.dataset.selectInitialized=!0,e.dispatchEvent(new CustomEvent("basecoat:initialized"))};window.basecoat&&window.basecoat.register("select","div.select:not([data-select-initialized])",e)})(),(()=>{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,n="true"===e.dataset.initialMobileOpen,i=parseInt(e.dataset.breakpoint)||768;let a=i>0?window.innerWidth>=i?t:n: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",!a),a?e.removeAttribute("inert"):e.setAttribute("inert","")},s=e=>{a=e,r()},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(!a)}})),e.addEventListener("click",(t=>{const n=t.target,a=e.querySelector("nav");if(window.innerWidth<i&&n.closest("a, button")&&!n.closest("[data-keep-mobile-sidebar-open]"))return document.activeElement&&document.activeElement.blur(),void s(!1);(n===e||a&&!a.contains(n))&&(document.activeElement&&document.activeElement.blur(),s(!1))})),window.addEventListener("popstate",o),window.addEventListener("basecoat:locationchange",o),r(),o(),e.dataset.sidebarInitialized=!0,e.dispatchEvent(new CustomEvent("basecoat:initialized"))};window.basecoat&&window.basecoat.register("sidebar",".sidebar:not([data-sidebar-initialized])",e)})(),(()=>{const e=e=>{const t=e.querySelector('[role="tablist"]');if(!t)return;const n=Array.from(t.querySelectorAll('[role="tab"]')),i=n.map((e=>document.getElementById(e.getAttribute("aria-controls")))).filter(Boolean),a=e=>{n.forEach(((e,t)=>{e.setAttribute("aria-selected","false"),e.setAttribute("tabindex","-1"),i[t]&&(i[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&&a(t)})),t.addEventListener("keydown",(e=>{const t=e.target;if(!n.includes(t))return;let i;const o=n.indexOf(t);switch(e.key){case"ArrowRight":i=n[(o+1)%n.length];break;case"ArrowLeft":i=n[(o-1+n.length)%n.length];break;case"Home":i=n[0];break;case"End":i=n[n.length-1];break;default:return}e.preventDefault(),a(i),i.focus()})),e.dataset.tabsInitialized=!0,e.dispatchEvent(new CustomEvent("basecoat:initialized"))};window.basecoat&&window.basecoat.register("tabs",".tabs:not([data-tabs-initialized])",e)})(),(()=>{let e;const t=new WeakMap;let n=!1;const i={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 a(e){if(e.dataset.toastInitialized)return;const i=parseInt(e.dataset.duration),a=-1!==i?i||("error"===e.dataset.category?5e3:3e3):-1,o={remainingTime:a,timeoutId:null,startTime:null};-1!==a&&(n?o.timeoutId=null:(o.startTime=Date.now(),o.timeoutId=setTimeout((()=>s(e)),a))),t.set(e,o),e.dataset.toastInitialized="true"}function o(){n||(n=!0,e.querySelectorAll('.toast:not([aria-hidden="true"])').forEach((e=>{if(!t.has(e))return;const n=t.get(e);n.timeoutId&&(clearTimeout(n.timeoutId),n.timeoutId=null,n.remainingTime-=Date.now()-n.startTime)})))}function r(){n&&(n=!1,e.querySelectorAll('.toast:not([aria-hidden="true"])').forEach((e=>{if(!t.has(e))return;const n=t.get(e);-1===n.remainingTime||n.timeoutId||(n.remainingTime>0?(n.startTime=Date.now(),n.timeoutId=setTimeout((()=>s(e)),n.remainingTime)):s(e))})))}function s(e){if(!t.has(e))return;const n=t.get(e);clearTimeout(n.timeoutId),t.delete(e),e.contains(document.activeElement)&&document.activeElement.blur(),e.setAttribute("aria-hidden","true"),e.addEventListener("transitionend",(()=>e.remove()),{once:!0})}document.addEventListener("basecoat:toast",(t=>{if(!e)return void console.error("Cannot create toast: toaster container not found on page.");const n=function(e){const{category:t="info",title:n,description:a,action:o,cancel:r,duration:s,icon:d}=e,c=d||t&&i[t]||"",l=n?`<h2>${n}</h2>`:"",u=a?`<p>${a}</p>`:"",v=o?.href?`<a href="${o.href}" class="btn" data-toast-action>${o.label}</a>`:o?.onclick?`<button type="button" class="btn" data-toast-action onclick="${o.onclick}">${o.label}</button>`:"",p=r?`<button type="button" class="btn-outline h-6 text-xs px-2.5 rounded-sm" data-toast-cancel onclick="${r?.onclick}">${r.label}</button>`:"",m=`\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 ${v||p?`<footer>${v}${p}</footer>`:""}\n </div>\n </div>\n </div>\n `,b=document.createElement("template");return b.innerHTML=m.trim(),b.content.firstChild}(t.detail?.config||{});e.appendChild(n)})),window.basecoat&&(window.basecoat.register("toaster","#toaster:not([data-toaster-initialized])",(function(t){t.dataset.toasterInitialized||(e=t,e.addEventListener("mouseenter",o),e.addEventListener("mouseleave",r),e.addEventListener("click",(e=>{const t=e.target.closest(".toast footer a"),n=e.target.closest(".toast footer button");(t||n)&&s(e.target.closest(".toast"))})),e.querySelectorAll(".toast:not([data-toast-initialized])").forEach(a),e.dataset.toasterInitialized="true",e.dispatchEvent(new CustomEvent("basecoat:initialized")))})),window.basecoat.register("toast",".toast:not([data-toast-initialized])",a))})();
|
|
1
|
+
(()=>{const e={};let t=null;const n=()=>{Object.entries(e).forEach((([e,{selector:t,init:n}])=>{document.querySelectorAll(t).forEach(n)}))},i=t=>{t.nodeType===Node.ELEMENT_NODE&&Object.entries(e).forEach((([e,{selector:n,init:i}])=>{t.matches(n)&&i(t),t.querySelectorAll(n).forEach(i)}))},a=()=>{t||(t=new MutationObserver((e=>{e.forEach((e=>{e.addedNodes.forEach(i)}))})),t.observe(document.body,{childList:!0,subtree:!0}))};window.basecoat={register:(t,n,i)=>{e[t]={selector:n,init:i}},init:t=>{const n=e[t];if(!n)return void console.warn(`Component '${t}' not found in registry`);const i=`data-${t}-initialized`;document.querySelectorAll(`[${i}]`).forEach((e=>{e.removeAttribute(i)})),document.querySelectorAll(n.selector).forEach(n.init)},initAll:()=>{Object.entries(e).forEach((([e,{selector:t}])=>{const n=`data-${e}-initialized`;document.querySelectorAll(`[${n}]`).forEach((e=>{e.removeAttribute(n)}))})),n()},start:a,stop:()=>{t&&(t.disconnect(),t=null)}},document.addEventListener("DOMContentLoaded",(()=>{n(),a()}))})(),(()=>{const e=e=>{const t=e.querySelector("header input"),n=e.querySelector('[role="menu"]');if(!t||!n){const i=[];return t||i.push("input"),n||i.push("menu"),void console.error(`Command component initialization failed. Missing element(s): ${i.join(", ")}`,e)}const i=Array.from(n.querySelectorAll('[role="menuitem"]')),a=i.filter((e=>!e.hasAttribute("disabled")&&"true"!==e.getAttribute("aria-disabled")));let r=[...a],o=-1;const s=e=>{if(o>-1&&a[o]&&a[o].classList.remove("active"),o=e,o>-1){const e=a[o];e.classList.add("active"),e.id?t.setAttribute("aria-activedescendant",e.id):t.removeAttribute("aria-activedescendant")}else t.removeAttribute("aria-activedescendant")};t.addEventListener("input",(()=>{const e=t.value.trim().toLowerCase();s(-1),r=[],i.forEach((t=>{if(t.hasAttribute("data-force"))return t.setAttribute("aria-hidden","false"),void(a.includes(t)&&r.push(t));const n=(t.dataset.filter||t.textContent).trim().toLowerCase(),i=(t.dataset.keywords||"").toLowerCase().split(/[\s,]+/).filter(Boolean).some((t=>t.includes(e))),o=n.includes(e)||i;t.setAttribute("aria-hidden",String(!o)),o&&a.includes(t)&&r.push(t)})),r.length>0&&(s(a.indexOf(r[0])),r[0].scrollIntoView({block:"nearest"}))}));n.addEventListener("mousemove",(e=>{const t=e.target.closest('[role="menuitem"]');if(t&&r.includes(t)){const e=a.indexOf(t);e!==o&&s(e)}})),n.addEventListener("click",(t=>{const n=t.target.closest('[role="menuitem"]');if(n&&r.includes(n)){const t=e.closest("dialog.command-dialog");t&&!n.hasAttribute("data-keep-command-open")&&t.close()}})),t.addEventListener("keydown",(e=>{if(!["ArrowDown","ArrowUp","Enter","Home","End"].includes(e.key))return;if("Enter"===e.key)return e.preventDefault(),void(o>-1&&a[o]?.click());if(0===r.length)return;e.preventDefault();const t=o>-1?r.indexOf(a[o]):-1;let n=t;switch(e.key){case"ArrowDown":t<r.length-1&&(n=t+1);break;case"ArrowUp":t>0?n=t-1:-1===t&&(n=0);break;case"Home":n=0;break;case"End":n=r.length-1}if(n!==t){const e=r[n];s(a.indexOf(e)),e.scrollIntoView({block:"nearest",behavior:"smooth"})}})),r.length>0&&(s(a.indexOf(r[0])),r[0].scrollIntoView({block:"nearest"})),e.dataset.commandInitialized=!0,e.dispatchEvent(new CustomEvent("basecoat:initialized"))};window.basecoat&&window.basecoat.register("command",".command:not([data-command-initialized])",e)})(),(()=>{const e=e=>{const t=e.querySelector(":scope > button"),n=e.querySelector(":scope > [data-popover]"),i=n.querySelector('[role="menu"]');if(!t||!i||!n){const a=[];return t||a.push("trigger"),i||a.push("menu"),n||a.push("popover"),void console.error(`Dropdown menu initialisation failed. Missing element(s): ${a.join(", ")}`,e)}let a=[],r=-1;const o=(e=!0)=>{"false"!==t.getAttribute("aria-expanded")&&(t.setAttribute("aria-expanded","false"),t.removeAttribute("aria-activedescendant"),n.setAttribute("aria-hidden","true"),e&&t.focus(),d(-1))},s=(r=!1)=>{document.dispatchEvent(new CustomEvent("basecoat:popover",{detail:{source:e}})),t.setAttribute("aria-expanded","true"),n.setAttribute("aria-hidden","false"),a=Array.from(i.querySelectorAll('[role^="menuitem"]')).filter((e=>!e.hasAttribute("disabled")&&"true"!==e.getAttribute("aria-disabled"))),a.length>0&&r&&("first"===r?d(0):"last"===r&&d(a.length-1))},d=e=>{if(r>-1&&a[r]&&a[r].classList.remove("active"),r=e,r>-1&&a[r]){const e=a[r];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(!1)})),e.addEventListener("keydown",(e=>{const n="true"===t.getAttribute("aria-expanded");if("Escape"===e.key)return void(n&&o());if(!n)return void(["Enter"," "].includes(e.key)?(e.preventDefault(),s(!1)):"ArrowDown"===e.key?(e.preventDefault(),s("first")):"ArrowUp"===e.key&&(e.preventDefault(),s("last")));if(0===a.length)return;let i=r;switch(e.key){case"ArrowDown":e.preventDefault(),i=-1===r?0:Math.min(r+1,a.length-1);break;case"ArrowUp":e.preventDefault(),i=-1===r?a.length-1:Math.max(r-1,0);break;case"Home":e.preventDefault(),i=0;break;case"End":e.preventDefault(),i=a.length-1;break;case"Enter":case" ":return e.preventDefault(),a[r]?.click(),void o()}i!==r&&d(i)})),i.addEventListener("mousemove",(e=>{const t=e.target.closest('[role^="menuitem"]');if(t&&a.includes(t)){const e=a.indexOf(t);e!==r&&d(e)}})),i.addEventListener("mouseleave",(()=>{d(-1)})),i.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,e.dispatchEvent(new CustomEvent("basecoat:initialized"))};window.basecoat&&window.basecoat.register("dropdown-menu",".dropdown-menu:not([data-dropdown-menu-initialized])",e)})(),(()=>{const e=e=>{const t=e.querySelector(":scope > button"),n=e.querySelector(":scope > [data-popover]");if(!t||!n){const i=[];return t||i.push("trigger"),n||i.push("content"),void console.error(`Popover initialisation failed. Missing element(s): ${i.join(", ")}`,e)}const i=(e=!0)=>{"false"!==t.getAttribute("aria-expanded")&&(t.setAttribute("aria-expanded","false"),n.setAttribute("aria-hidden","true"),e&&t.focus())};t.addEventListener("click",(()=>{"true"===t.getAttribute("aria-expanded")?i():(()=>{document.dispatchEvent(new CustomEvent("basecoat:popover",{detail:{source:e}}));const i=n.querySelector("[autofocus]");i&&n.addEventListener("transitionend",(()=>{i.focus()}),{once:!0}),t.setAttribute("aria-expanded","true"),n.setAttribute("aria-hidden","false")})()})),e.addEventListener("keydown",(e=>{"Escape"===e.key&&i()})),document.addEventListener("click",(t=>{e.contains(t.target)||i()})),document.addEventListener("basecoat:popover",(t=>{t.detail.source!==e&&i(!1)})),e.dataset.popoverInitialized=!0,e.dispatchEvent(new CustomEvent("basecoat:initialized"))};window.basecoat&&window.basecoat.register("popover",".popover:not([data-popover-initialized])",e)})(),(()=>{const e=e=>{const t=e.querySelector(":scope > button"),n=t.querySelector(":scope > span"),i=e.querySelector(":scope > [data-popover]"),a=i?i.querySelector('[role="listbox"]'):null,r=e.querySelector(':scope > input[type="hidden"]'),o=e.querySelector('header input[type="text"]');if(!(t&&i&&a&&r)){const n=[];return t||n.push("trigger"),i||n.push("popover"),a||n.push("listbox"),r||n.push("input"),void console.error(`Select component initialisation failed. Missing element(s): ${n.join(", ")}`,e)}const s=Array.from(a.querySelectorAll('[role="option"]')),d=s.filter((e=>"true"!==e.getAttribute("aria-disabled")));let c=[...d],l=-1;const u="true"===a.getAttribute("aria-multiselectable"),p=u?new Set:null,v=u?e.dataset.placeholder||"":null,h=e=>e.dataset.value??e.textContent.trim(),f=e=>{if(l>-1&&d[l]&&d[l].classList.remove("active"),l=e,l>-1){const e=d[l];e.classList.add("active"),e.id?t.setAttribute("aria-activedescendant",e.id):t.removeAttribute("aria-activedescendant")}else t.removeAttribute("aria-activedescendant")},m=()=>{const e=getComputedStyle(i);return parseFloat(e.transitionDuration)>0||parseFloat(e.transitionDelay)>0},b=(t,i=!0)=>{let a;if(u){const e=Array.isArray(t)?t:[];p.clear(),e.forEach((e=>p.add(e)));const i=d.filter((e=>p.has(e)));0===i.length?(n.textContent=v,n.classList.add("text-muted-foreground")):(n.textContent=i.map((e=>e.dataset.label||e.textContent.trim())).join(", "),n.classList.remove("text-muted-foreground")),a=i.map(h),r.value=JSON.stringify(a)}else{const e=t;if(!e)return;n.innerHTML=e.innerHTML,a=h(e),r.value=a}d.forEach((e=>{(u?p.has(e):e===t)?e.setAttribute("aria-selected","true"):e.removeAttribute("aria-selected")})),i&&e.dispatchEvent(new CustomEvent("change",{detail:{value:a},bubbles:!0}))},w=(e=!0)=>{if("true"!==i.getAttribute("aria-hidden")){if(o){const e=()=>{o.value="",c=[...d],s.forEach((e=>e.setAttribute("aria-hidden","false")))};m()?i.addEventListener("transitionend",e,{once:!0}):e()}e&&t.focus(),i.setAttribute("aria-hidden","true"),t.setAttribute("aria-expanded","false"),f(-1)}},g=e=>{p.has(e)?p.delete(e):p.add(e),b(d.filter((e=>p.has(e))))},E=e=>{if(u){const t=d.find((t=>h(t)===e&&!p.has(t)));if(!t)return;p.add(t),b(d.filter((e=>p.has(e))))}else{const t=d.find((t=>h(t)===e));if(!t)return;r.value!==e&&b(t),w()}},A=e=>{if(!u)return;const t=d.find((t=>h(t)===e&&p.has(t)));t&&(p.delete(t),b(d.filter((e=>p.has(e)))))},y=e=>{if(!u)return;const t=d.find((t=>h(t)===e));t&&g(t)};if(o){const e=()=>{const e=o.value.trim().toLowerCase();f(-1),c=[],s.forEach((t=>{if(t.hasAttribute("data-force"))return t.setAttribute("aria-hidden","false"),void(d.includes(t)&&c.push(t));const n=(t.dataset.filter||t.textContent).trim().toLowerCase(),i=(t.dataset.keywords||"").toLowerCase().split(/[\s,]+/).filter(Boolean).some((t=>t.includes(e))),a=n.includes(e)||i;t.setAttribute("aria-hidden",String(!a)),a&&d.includes(t)&&c.push(t)}))};o.addEventListener("input",e)}if(u){const e=d.filter((e=>"true"===e.getAttribute("aria-selected")));try{const t=JSON.parse(r.value||"[]"),n=new Set(d.map(h)),i=Array.isArray(t)?t.filter((e=>n.has(e))):[],a=[];i.length>0?i.forEach((e=>{const t=d.find((t=>h(t)===e&&!a.includes(t)));t&&a.push(t)})):a.push(...e),b(a,!1)}catch(t){b(e,!1)}}else{const e=d.find((e=>h(e)===r.value))||d[0];e&&b(e,!1)}const k=e=>{const n="false"===i.getAttribute("aria-hidden");if(!["ArrowDown","ArrowUp","Enter","Home","End","Escape"].includes(e.key))return;if(!n)return void("Enter"!==e.key&&"Escape"!==e.key&&(e.preventDefault(),t.click()));if(e.preventDefault(),"Escape"===e.key)return void w();if("Enter"===e.key){if(l>-1){const e=d[l];u?g(e):(r.value!==h(e)&&b(e),w())}return}if(0===c.length)return;const a=l>-1?c.indexOf(d[l]):-1;let o=a;switch(e.key){case"ArrowDown":a<c.length-1&&(o=a+1);break;case"ArrowUp":a>0?o=a-1:-1===a&&(o=0);break;case"Home":o=0;break;case"End":o=c.length-1}if(o!==a){const e=c[o];f(d.indexOf(e)),e.scrollIntoView({block:"nearest",behavior:"smooth"})}};a.addEventListener("mousemove",(e=>{const t=e.target.closest('[role="option"]');if(t&&c.includes(t)){const e=d.indexOf(t);e!==l&&f(e)}})),a.addEventListener("mouseleave",(()=>{const e=a.querySelector('[role="option"][aria-selected="true"]');f(e?d.indexOf(e):-1)})),t.addEventListener("keydown",k),o&&o.addEventListener("keydown",k);t.addEventListener("click",(()=>{"true"===t.getAttribute("aria-expanded")?w():(()=>{document.dispatchEvent(new CustomEvent("basecoat:popover",{detail:{source:e}})),o&&(m()?i.addEventListener("transitionend",(()=>{o.focus()}),{once:!0}):o.focus()),i.setAttribute("aria-hidden","false"),t.setAttribute("aria-expanded","true");const n=a.querySelector('[role="option"][aria-selected="true"]');n&&(f(d.indexOf(n)),n.scrollIntoView({block:"nearest"}))})()})),a.addEventListener("click",(e=>{const n=e.target.closest('[role="option"]');if(!n)return;const i=d.find((e=>e===n));i&&(u?(g(i),f(d.indexOf(i)),o?o.focus():t.focus()):(r.value!==h(i)&&b(i),w()))})),document.addEventListener("click",(t=>{e.contains(t.target)||w(!1)})),document.addEventListener("basecoat:popover",(t=>{t.detail.source!==e&&w(!1)})),i.setAttribute("aria-hidden","true"),Object.defineProperty(e,"value",{get:()=>u?d.filter((e=>p.has(e))).map(h):r.value,set:e=>{if(u){const t=Array.isArray(e)?e:null!=e?[e]:[],n=[];t.forEach((e=>{const t=d.find((t=>h(t)===e&&!n.includes(t)));t&&n.push(t)})),b(n)}else{const t=d.find((t=>h(t)===e));t&&(b(t),w())}}}),e.select=E,e.selectByValue=E,u&&(e.deselect=A,e.toggle=y,e.selectAll=()=>b(d),e.selectNone=()=>b([])),e.dataset.selectInitialized=!0,e.dispatchEvent(new CustomEvent("basecoat:initialized"))};window.basecoat&&window.basecoat.register("select","div.select:not([data-select-initialized])",e)})(),(()=>{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,n="true"===e.dataset.initialMobileOpen,i=parseInt(e.dataset.breakpoint)||768;let a=i>0?window.innerWidth>=i?t:n:t;const r=()=>{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",!a),a?e.removeAttribute("inert"):e.setAttribute("inert","")},s=e=>{a=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(!a)}})),e.addEventListener("click",(t=>{const n=t.target,a=e.querySelector("nav");if(window.innerWidth<i&&n.closest("a, button")&&!n.closest("[data-keep-mobile-sidebar-open]"))return document.activeElement&&document.activeElement.blur(),void s(!1);(n===e||a&&!a.contains(n))&&(document.activeElement&&document.activeElement.blur(),s(!1))})),window.addEventListener("popstate",r),window.addEventListener("basecoat:locationchange",r),o(),r(),e.dataset.sidebarInitialized=!0,e.dispatchEvent(new CustomEvent("basecoat:initialized"))};window.basecoat&&window.basecoat.register("sidebar",".sidebar:not([data-sidebar-initialized])",e)})(),(()=>{const e=e=>{const t=e.querySelector('[role="tablist"]');if(!t)return;const n=Array.from(t.querySelectorAll('[role="tab"]')),i=n.map((e=>document.getElementById(e.getAttribute("aria-controls")))).filter(Boolean),a=e=>{n.forEach(((e,t)=>{e.setAttribute("aria-selected","false"),e.setAttribute("tabindex","-1"),i[t]&&(i[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&&a(t)})),t.addEventListener("keydown",(e=>{const t=e.target;if(!n.includes(t))return;let i;const r=n.indexOf(t);switch(e.key){case"ArrowRight":i=n[(r+1)%n.length];break;case"ArrowLeft":i=n[(r-1+n.length)%n.length];break;case"Home":i=n[0];break;case"End":i=n[n.length-1];break;default:return}e.preventDefault(),a(i),i.focus()})),e.dataset.tabsInitialized=!0,e.dispatchEvent(new CustomEvent("basecoat:initialized"))};window.basecoat&&window.basecoat.register("tabs",".tabs:not([data-tabs-initialized])",e)})(),(()=>{let e;const t=new WeakMap;let n=!1;const i={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 a(e){if(e.dataset.toastInitialized)return;const i=parseInt(e.dataset.duration),a=-1!==i?i||("error"===e.dataset.category?5e3:3e3):-1,r={remainingTime:a,timeoutId:null,startTime:null};-1!==a&&(n?r.timeoutId=null:(r.startTime=Date.now(),r.timeoutId=setTimeout((()=>s(e)),a))),t.set(e,r),e.dataset.toastInitialized="true"}function r(){n||(n=!0,e.querySelectorAll('.toast:not([aria-hidden="true"])').forEach((e=>{if(!t.has(e))return;const n=t.get(e);n.timeoutId&&(clearTimeout(n.timeoutId),n.timeoutId=null,n.remainingTime-=Date.now()-n.startTime)})))}function o(){n&&(n=!1,e.querySelectorAll('.toast:not([aria-hidden="true"])').forEach((e=>{if(!t.has(e))return;const n=t.get(e);-1===n.remainingTime||n.timeoutId||(n.remainingTime>0?(n.startTime=Date.now(),n.timeoutId=setTimeout((()=>s(e)),n.remainingTime)):s(e))})))}function s(e){if(!t.has(e))return;const n=t.get(e);clearTimeout(n.timeoutId),t.delete(e),e.contains(document.activeElement)&&document.activeElement.blur(),e.setAttribute("aria-hidden","true"),e.addEventListener("transitionend",(()=>e.remove()),{once:!0})}document.addEventListener("basecoat:toast",(t=>{if(!e)return void console.error("Cannot create toast: toaster container not found on page.");const n=function(e){const{category:t="info",title:n,description:a,action:r,cancel:o,duration:s,icon:d}=e,c=d||t&&i[t]||"",l=n?`<h2>${n}</h2>`:"",u=a?`<p>${a}</p>`:"",p=r?.href?`<a href="${r.href}" class="btn" data-toast-action>${r.label}</a>`:r?.onclick?`<button type="button" class="btn" data-toast-action onclick="${r.onclick}">${r.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>`:"",h=`\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||v?`<footer>${p}${v}</footer>`:""}\n </div>\n </div>\n </div>\n `,f=document.createElement("template");return f.innerHTML=h.trim(),f.content.firstChild}(t.detail?.config||{});e.appendChild(n)})),window.basecoat&&(window.basecoat.register("toaster","#toaster:not([data-toaster-initialized])",(function(t){t.dataset.toasterInitialized||(e=t,e.addEventListener("mouseenter",r),e.addEventListener("mouseleave",o),e.addEventListener("click",(e=>{const t=e.target.closest(".toast footer a"),n=e.target.closest(".toast footer button");(t||n)&&s(e.target.closest(".toast"))})),e.querySelectorAll(".toast:not([data-toast-initialized])").forEach(a),e.dataset.toasterInitialized="true",e.dispatchEvent(new CustomEvent("basecoat:initialized")))})),window.basecoat.register("toast",".toast:not([data-toast-initialized])",a))})();
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
const initCarousel = (carouselComponent) => {
|
|
3
|
+
const slidesContainer = carouselComponent.querySelector('.carousel-slides');
|
|
4
|
+
if (!slidesContainer) return;
|
|
5
|
+
|
|
6
|
+
const slides = Array.from(carouselComponent.querySelectorAll('.carousel-item'));
|
|
7
|
+
const prevButton = carouselComponent.querySelector('.carousel-prev');
|
|
8
|
+
const nextButton = carouselComponent.querySelector('.carousel-next');
|
|
9
|
+
const indicators = Array.from(carouselComponent.querySelectorAll('.carousel-indicators button'));
|
|
10
|
+
|
|
11
|
+
const loop = carouselComponent.dataset.carouselLoop === 'true';
|
|
12
|
+
const autoplayDelay = parseInt(carouselComponent.dataset.carouselAutoplay, 10);
|
|
13
|
+
const orientation = carouselComponent.dataset.orientation || 'horizontal';
|
|
14
|
+
|
|
15
|
+
let currentIndex = 0;
|
|
16
|
+
let autoplayInterval = null;
|
|
17
|
+
|
|
18
|
+
const getScrollAmount = () => {
|
|
19
|
+
if (slides.length === 0) return 0;
|
|
20
|
+
const firstSlide = slides[0];
|
|
21
|
+
return orientation === 'vertical'
|
|
22
|
+
? firstSlide.offsetHeight + parseInt(getComputedStyle(slidesContainer).gap || 0)
|
|
23
|
+
: firstSlide.offsetWidth + parseInt(getComputedStyle(slidesContainer).gap || 0);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const scrollToIndex = (index) => {
|
|
27
|
+
const scrollAmount = getScrollAmount();
|
|
28
|
+
if (orientation === 'vertical') {
|
|
29
|
+
slidesContainer.scrollTo({ top: scrollAmount * index, behavior: 'smooth' });
|
|
30
|
+
} else {
|
|
31
|
+
slidesContainer.scrollTo({ left: scrollAmount * index, behavior: 'smooth' });
|
|
32
|
+
}
|
|
33
|
+
currentIndex = index;
|
|
34
|
+
updateIndicators();
|
|
35
|
+
updateButtonStates();
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const updateIndicators = () => {
|
|
39
|
+
indicators.forEach((indicator, index) => {
|
|
40
|
+
const isActive = index === currentIndex;
|
|
41
|
+
indicator.setAttribute('aria-current', isActive ? 'true' : 'false');
|
|
42
|
+
indicator.setAttribute('aria-label', `Slide ${index + 1}${isActive ? ' (current)' : ''}`);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
slides.forEach((slide, index) => {
|
|
46
|
+
slide.setAttribute('aria-hidden', index === currentIndex ? 'false' : 'true');
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const updateButtonStates = () => {
|
|
51
|
+
if (!prevButton || !nextButton) return;
|
|
52
|
+
|
|
53
|
+
if (loop) {
|
|
54
|
+
prevButton.disabled = false;
|
|
55
|
+
nextButton.disabled = false;
|
|
56
|
+
} else {
|
|
57
|
+
prevButton.disabled = currentIndex === 0;
|
|
58
|
+
nextButton.disabled = currentIndex === slides.length - 1;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const goToPrevious = () => {
|
|
63
|
+
if (currentIndex > 0) {
|
|
64
|
+
scrollToIndex(currentIndex - 1);
|
|
65
|
+
} else if (loop) {
|
|
66
|
+
scrollToIndex(slides.length - 1);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const goToNext = () => {
|
|
71
|
+
if (currentIndex < slides.length - 1) {
|
|
72
|
+
scrollToIndex(currentIndex + 1);
|
|
73
|
+
} else if (loop) {
|
|
74
|
+
scrollToIndex(0);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const startAutoplay = () => {
|
|
79
|
+
if (!autoplayDelay || autoplayDelay <= 0) return;
|
|
80
|
+
|
|
81
|
+
autoplayInterval = setInterval(() => {
|
|
82
|
+
goToNext();
|
|
83
|
+
}, autoplayDelay);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const stopAutoplay = () => {
|
|
87
|
+
if (autoplayInterval) {
|
|
88
|
+
clearInterval(autoplayInterval);
|
|
89
|
+
autoplayInterval = null;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const detectCurrentSlide = () => {
|
|
94
|
+
const scrollPosition = orientation === 'vertical'
|
|
95
|
+
? slidesContainer.scrollTop
|
|
96
|
+
: slidesContainer.scrollLeft;
|
|
97
|
+
const scrollAmount = getScrollAmount();
|
|
98
|
+
const newIndex = Math.round(scrollPosition / scrollAmount);
|
|
99
|
+
|
|
100
|
+
if (newIndex !== currentIndex && newIndex >= 0 && newIndex < slides.length) {
|
|
101
|
+
currentIndex = newIndex;
|
|
102
|
+
updateIndicators();
|
|
103
|
+
updateButtonStates();
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// Previous/Next button handlers
|
|
108
|
+
if (prevButton) {
|
|
109
|
+
prevButton.addEventListener('click', () => {
|
|
110
|
+
stopAutoplay();
|
|
111
|
+
goToPrevious();
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (nextButton) {
|
|
116
|
+
nextButton.addEventListener('click', () => {
|
|
117
|
+
stopAutoplay();
|
|
118
|
+
goToNext();
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Indicator click handlers
|
|
123
|
+
indicators.forEach((indicator, index) => {
|
|
124
|
+
indicator.addEventListener('click', () => {
|
|
125
|
+
stopAutoplay();
|
|
126
|
+
scrollToIndex(index);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// Keyboard navigation
|
|
131
|
+
carouselComponent.addEventListener('keydown', (event) => {
|
|
132
|
+
const isVertical = orientation === 'vertical';
|
|
133
|
+
const prevKey = isVertical ? 'ArrowUp' : 'ArrowLeft';
|
|
134
|
+
const nextKey = isVertical ? 'ArrowDown' : 'ArrowRight';
|
|
135
|
+
|
|
136
|
+
switch (event.key) {
|
|
137
|
+
case prevKey:
|
|
138
|
+
event.preventDefault();
|
|
139
|
+
stopAutoplay();
|
|
140
|
+
goToPrevious();
|
|
141
|
+
break;
|
|
142
|
+
case nextKey:
|
|
143
|
+
event.preventDefault();
|
|
144
|
+
stopAutoplay();
|
|
145
|
+
goToNext();
|
|
146
|
+
break;
|
|
147
|
+
case 'Home':
|
|
148
|
+
event.preventDefault();
|
|
149
|
+
stopAutoplay();
|
|
150
|
+
scrollToIndex(0);
|
|
151
|
+
break;
|
|
152
|
+
case 'End':
|
|
153
|
+
event.preventDefault();
|
|
154
|
+
stopAutoplay();
|
|
155
|
+
scrollToIndex(slides.length - 1);
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// Detect scroll position changes (for touch/manual scrolling)
|
|
161
|
+
let scrollTimeout;
|
|
162
|
+
slidesContainer.addEventListener('scroll', () => {
|
|
163
|
+
clearTimeout(scrollTimeout);
|
|
164
|
+
scrollTimeout = setTimeout(() => {
|
|
165
|
+
detectCurrentSlide();
|
|
166
|
+
}, 100);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// Pause autoplay on hover or focus
|
|
170
|
+
if (autoplayDelay) {
|
|
171
|
+
carouselComponent.addEventListener('mouseenter', stopAutoplay);
|
|
172
|
+
carouselComponent.addEventListener('mouseleave', startAutoplay);
|
|
173
|
+
carouselComponent.addEventListener('focusin', stopAutoplay);
|
|
174
|
+
carouselComponent.addEventListener('focusout', startAutoplay);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Initialize
|
|
178
|
+
updateIndicators();
|
|
179
|
+
updateButtonStates();
|
|
180
|
+
|
|
181
|
+
if (autoplayDelay) {
|
|
182
|
+
startAutoplay();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
carouselComponent.dataset.carouselInitialized = true;
|
|
186
|
+
carouselComponent.dispatchEvent(new CustomEvent('basecoat:initialized'));
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
if (window.basecoat) {
|
|
190
|
+
window.basecoat.register('carousel', '.carousel:not([data-carousel-initialized])', initCarousel);
|
|
191
|
+
}
|
|
192
|
+
})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(()=>{const e=e=>{const t=e.querySelector(".carousel-slides");if(!t)return;const r=Array.from(e.querySelectorAll(".carousel-item")),a=e.querySelector(".carousel-prev"),o=e.querySelector(".carousel-next"),l=Array.from(e.querySelectorAll(".carousel-indicators button")),s="true"===e.dataset.carouselLoop,n=parseInt(e.dataset.carouselAutoplay,10),i=e.dataset.orientation||"horizontal";let c=0,d=null;const u=()=>{if(0===r.length)return 0;const e=r[0];return"vertical"===i?e.offsetHeight+parseInt(getComputedStyle(t).gap||0):e.offsetWidth+parseInt(getComputedStyle(t).gap||0)},v=e=>{const r=u();"vertical"===i?t.scrollTo({top:r*e,behavior:"smooth"}):t.scrollTo({left:r*e,behavior:"smooth"}),c=e,f(),h()},f=()=>{l.forEach(((e,t)=>{const r=t===c;e.setAttribute("aria-current",r?"true":"false"),e.setAttribute("aria-label",`Slide ${t+1}${r?" (current)":""}`)})),r.forEach(((e,t)=>{e.setAttribute("aria-hidden",t===c?"false":"true")}))},h=()=>{a&&o&&(s?(a.disabled=!1,o.disabled=!1):(a.disabled=0===c,o.disabled=c===r.length-1))},p=()=>{c>0?v(c-1):s&&v(r.length-1)},b=()=>{c<r.length-1?v(c+1):s&&v(0)},E=()=>{!n||n<=0||(d=setInterval((()=>{b()}),n))},g=()=>{d&&(clearInterval(d),d=null)};let m;a&&a.addEventListener("click",(()=>{g(),p()})),o&&o.addEventListener("click",(()=>{g(),b()})),l.forEach(((e,t)=>{e.addEventListener("click",(()=>{g(),v(t)}))})),e.addEventListener("keydown",(e=>{const t="vertical"===i,a=t?"ArrowUp":"ArrowLeft",o=t?"ArrowDown":"ArrowRight";switch(e.key){case a:e.preventDefault(),g(),p();break;case o:e.preventDefault(),g(),b();break;case"Home":e.preventDefault(),g(),v(0);break;case"End":e.preventDefault(),g(),v(r.length-1)}})),t.addEventListener("scroll",(()=>{clearTimeout(m),m=setTimeout((()=>{(()=>{const e="vertical"===i?t.scrollTop:t.scrollLeft,a=u(),o=Math.round(e/a);o!==c&&o>=0&&o<r.length&&(c=o,f(),h())})()}),100)})),n&&(e.addEventListener("mouseenter",g),e.addEventListener("mouseleave",E),e.addEventListener("focusin",g),e.addEventListener("focusout",E)),f(),h(),n&&E(),e.dataset.carouselInitialized=!0,e.dispatchEvent(new CustomEvent("basecoat:initialized"))};window.basecoat&&window.basecoat.register("carousel",".carousel:not([data-carousel-initialized])",e)})();
|
package/dist/assets/js/select.js
CHANGED
|
@@ -3,31 +3,37 @@
|
|
|
3
3
|
const trigger = selectComponent.querySelector(':scope > button');
|
|
4
4
|
const selectedLabel = trigger.querySelector(':scope > span');
|
|
5
5
|
const popover = selectComponent.querySelector(':scope > [data-popover]');
|
|
6
|
-
const listbox = popover.querySelector('[role="listbox"]');
|
|
6
|
+
const listbox = popover ? popover.querySelector('[role="listbox"]') : null;
|
|
7
7
|
const input = selectComponent.querySelector(':scope > input[type="hidden"]');
|
|
8
8
|
const filter = selectComponent.querySelector('header input[type="text"]');
|
|
9
|
+
|
|
9
10
|
if (!trigger || !popover || !listbox || !input) {
|
|
10
11
|
const missing = [];
|
|
11
12
|
if (!trigger) missing.push('trigger');
|
|
12
13
|
if (!popover) missing.push('popover');
|
|
13
14
|
if (!listbox) missing.push('listbox');
|
|
14
|
-
if (!input)
|
|
15
|
+
if (!input) missing.push('input');
|
|
15
16
|
console.error(`Select component initialisation failed. Missing element(s): ${missing.join(', ')}`, selectComponent);
|
|
16
17
|
return;
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
+
|
|
19
20
|
const allOptions = Array.from(listbox.querySelectorAll('[role="option"]'));
|
|
20
21
|
const options = allOptions.filter(opt => opt.getAttribute('aria-disabled') !== 'true');
|
|
21
22
|
let visibleOptions = [...options];
|
|
22
23
|
let activeIndex = -1;
|
|
24
|
+
const isMultiple = listbox.getAttribute('aria-multiselectable') === 'true';
|
|
25
|
+
const selectedOptions = isMultiple ? new Set() : null;
|
|
26
|
+
const placeholder = isMultiple ? (selectComponent.dataset.placeholder || '') : null;
|
|
27
|
+
|
|
28
|
+
const getValue = (opt) => opt.dataset.value ?? opt.textContent.trim();
|
|
23
29
|
|
|
24
30
|
const setActiveOption = (index) => {
|
|
25
31
|
if (activeIndex > -1 && options[activeIndex]) {
|
|
26
32
|
options[activeIndex].classList.remove('active');
|
|
27
33
|
}
|
|
28
|
-
|
|
34
|
+
|
|
29
35
|
activeIndex = index;
|
|
30
|
-
|
|
36
|
+
|
|
31
37
|
if (activeIndex > -1) {
|
|
32
38
|
const activeOption = options[activeIndex];
|
|
33
39
|
activeOption.classList.add('active');
|
|
@@ -46,68 +52,118 @@
|
|
|
46
52
|
return parseFloat(style.transitionDuration) > 0 || parseFloat(style.transitionDelay) > 0;
|
|
47
53
|
};
|
|
48
54
|
|
|
49
|
-
const updateValue = (
|
|
50
|
-
|
|
55
|
+
const updateValue = (optionOrOptions, triggerEvent = true) => {
|
|
56
|
+
let value;
|
|
57
|
+
|
|
58
|
+
if (isMultiple) {
|
|
59
|
+
const opts = Array.isArray(optionOrOptions) ? optionOrOptions : [];
|
|
60
|
+
selectedOptions.clear();
|
|
61
|
+
opts.forEach(opt => selectedOptions.add(opt));
|
|
62
|
+
|
|
63
|
+
// Get selected options in DOM order
|
|
64
|
+
const selected = options.filter(opt => selectedOptions.has(opt));
|
|
65
|
+
if (selected.length === 0) {
|
|
66
|
+
selectedLabel.textContent = placeholder;
|
|
67
|
+
selectedLabel.classList.add('text-muted-foreground');
|
|
68
|
+
} else {
|
|
69
|
+
selectedLabel.textContent = selected.map(opt => opt.dataset.label || opt.textContent.trim()).join(', ');
|
|
70
|
+
selectedLabel.classList.remove('text-muted-foreground');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
value = selected.map(getValue);
|
|
74
|
+
input.value = JSON.stringify(value);
|
|
75
|
+
} else {
|
|
76
|
+
const option = optionOrOptions;
|
|
77
|
+
if (!option) return;
|
|
51
78
|
selectedLabel.innerHTML = option.innerHTML;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
79
|
+
value = getValue(option);
|
|
80
|
+
input.value = value;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
options.forEach(opt => {
|
|
84
|
+
const isSelected = isMultiple ? selectedOptions.has(opt) : opt === optionOrOptions;
|
|
85
|
+
if (isSelected) {
|
|
86
|
+
opt.setAttribute('aria-selected', 'true');
|
|
87
|
+
} else {
|
|
88
|
+
opt.removeAttribute('aria-selected');
|
|
62
89
|
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
if (triggerEvent) {
|
|
93
|
+
selectComponent.dispatchEvent(new CustomEvent('change', {
|
|
94
|
+
detail: { value },
|
|
95
|
+
bubbles: true
|
|
96
|
+
}));
|
|
63
97
|
}
|
|
64
98
|
};
|
|
65
99
|
|
|
66
100
|
const closePopover = (focusOnTrigger = true) => {
|
|
67
101
|
if (popover.getAttribute('aria-hidden') === 'true') return;
|
|
68
|
-
|
|
102
|
+
|
|
69
103
|
if (filter) {
|
|
70
104
|
const resetFilter = () => {
|
|
71
105
|
filter.value = '';
|
|
72
106
|
visibleOptions = [...options];
|
|
73
107
|
allOptions.forEach(opt => opt.setAttribute('aria-hidden', 'false'));
|
|
74
108
|
};
|
|
75
|
-
|
|
109
|
+
|
|
76
110
|
if (hasTransition()) {
|
|
77
111
|
popover.addEventListener('transitionend', resetFilter, { once: true });
|
|
78
112
|
} else {
|
|
79
113
|
resetFilter();
|
|
80
114
|
}
|
|
81
115
|
}
|
|
82
|
-
|
|
116
|
+
|
|
83
117
|
if (focusOnTrigger) trigger.focus();
|
|
84
118
|
popover.setAttribute('aria-hidden', 'true');
|
|
85
119
|
trigger.setAttribute('aria-expanded', 'false');
|
|
86
120
|
setActiveOption(-1);
|
|
87
|
-
}
|
|
121
|
+
};
|
|
88
122
|
|
|
89
|
-
const
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
123
|
+
const toggleMultipleValue = (option) => {
|
|
124
|
+
if (selectedOptions.has(option)) {
|
|
125
|
+
selectedOptions.delete(option);
|
|
126
|
+
} else {
|
|
127
|
+
selectedOptions.add(option);
|
|
128
|
+
}
|
|
129
|
+
updateValue(options.filter(opt => selectedOptions.has(opt)));
|
|
130
|
+
};
|
|
94
131
|
|
|
95
|
-
|
|
96
|
-
|
|
132
|
+
const select = (value) => {
|
|
133
|
+
if (isMultiple) {
|
|
134
|
+
const option = options.find(opt => getValue(opt) === value && !selectedOptions.has(opt));
|
|
135
|
+
if (!option) return;
|
|
136
|
+
selectedOptions.add(option);
|
|
137
|
+
updateValue(options.filter(opt => selectedOptions.has(opt)));
|
|
138
|
+
} else {
|
|
139
|
+
const option = options.find(opt => getValue(opt) === value);
|
|
140
|
+
if (!option) return;
|
|
141
|
+
if (input.value !== value) {
|
|
142
|
+
updateValue(option);
|
|
143
|
+
}
|
|
144
|
+
closePopover();
|
|
97
145
|
}
|
|
98
|
-
|
|
99
|
-
closePopover();
|
|
100
146
|
};
|
|
101
147
|
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
148
|
+
const deselect = (value) => {
|
|
149
|
+
if (!isMultiple) return;
|
|
150
|
+
const option = options.find(opt => getValue(opt) === value && selectedOptions.has(opt));
|
|
151
|
+
if (!option) return;
|
|
152
|
+
selectedOptions.delete(option);
|
|
153
|
+
updateValue(options.filter(opt => selectedOptions.has(opt)));
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const toggle = (value) => {
|
|
157
|
+
if (!isMultiple) return;
|
|
158
|
+
const option = options.find(opt => getValue(opt) === value);
|
|
159
|
+
if (!option) return;
|
|
160
|
+
toggleMultipleValue(option);
|
|
105
161
|
};
|
|
106
162
|
|
|
107
163
|
if (filter) {
|
|
108
164
|
const filterOptions = () => {
|
|
109
165
|
const searchTerm = filter.value.trim().toLowerCase();
|
|
110
|
-
|
|
166
|
+
|
|
111
167
|
setActiveOption(-1);
|
|
112
168
|
|
|
113
169
|
visibleOptions = [];
|
|
@@ -133,17 +189,37 @@
|
|
|
133
189
|
}
|
|
134
190
|
});
|
|
135
191
|
};
|
|
136
|
-
|
|
192
|
+
|
|
137
193
|
filter.addEventListener('input', filterOptions);
|
|
138
194
|
}
|
|
139
195
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
196
|
+
// Initialization
|
|
197
|
+
if (isMultiple) {
|
|
198
|
+
const ariaSelected = options.filter(opt => opt.getAttribute('aria-selected') === 'true');
|
|
199
|
+
try {
|
|
200
|
+
const parsed = JSON.parse(input.value || '[]');
|
|
201
|
+
const validValues = new Set(options.map(getValue));
|
|
202
|
+
const initialValues = Array.isArray(parsed) ? parsed.filter(v => validValues.has(v)) : [];
|
|
145
203
|
|
|
146
|
-
|
|
204
|
+
const initialOptions = [];
|
|
205
|
+
if (initialValues.length > 0) {
|
|
206
|
+
// Match values to options in order, allowing duplicates
|
|
207
|
+
initialValues.forEach(val => {
|
|
208
|
+
const opt = options.find(o => getValue(o) === val && !initialOptions.includes(o));
|
|
209
|
+
if (opt) initialOptions.push(opt);
|
|
210
|
+
});
|
|
211
|
+
} else {
|
|
212
|
+
initialOptions.push(...ariaSelected);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
updateValue(initialOptions, false);
|
|
216
|
+
} catch (e) {
|
|
217
|
+
updateValue(ariaSelected, false);
|
|
218
|
+
}
|
|
219
|
+
} else {
|
|
220
|
+
const initialOption = options.find(opt => getValue(opt) === input.value) || options[0];
|
|
221
|
+
if (initialOption) updateValue(initialOption, false);
|
|
222
|
+
}
|
|
147
223
|
|
|
148
224
|
const handleKeyNavigation = (event) => {
|
|
149
225
|
const isPopoverOpen = popover.getAttribute('aria-hidden') === 'false';
|
|
@@ -159,17 +235,25 @@
|
|
|
159
235
|
}
|
|
160
236
|
return;
|
|
161
237
|
}
|
|
162
|
-
|
|
238
|
+
|
|
163
239
|
event.preventDefault();
|
|
164
240
|
|
|
165
241
|
if (event.key === 'Escape') {
|
|
166
242
|
closePopover();
|
|
167
243
|
return;
|
|
168
244
|
}
|
|
169
|
-
|
|
245
|
+
|
|
170
246
|
if (event.key === 'Enter') {
|
|
171
247
|
if (activeIndex > -1) {
|
|
172
|
-
|
|
248
|
+
const option = options[activeIndex];
|
|
249
|
+
if (isMultiple) {
|
|
250
|
+
toggleMultipleValue(option);
|
|
251
|
+
} else {
|
|
252
|
+
if (input.value !== getValue(option)) {
|
|
253
|
+
updateValue(option);
|
|
254
|
+
}
|
|
255
|
+
closePopover();
|
|
256
|
+
}
|
|
173
257
|
}
|
|
174
258
|
return;
|
|
175
259
|
}
|
|
@@ -235,7 +319,7 @@
|
|
|
235
319
|
document.dispatchEvent(new CustomEvent('basecoat:popover', {
|
|
236
320
|
detail: { source: selectComponent }
|
|
237
321
|
}));
|
|
238
|
-
|
|
322
|
+
|
|
239
323
|
if (filter) {
|
|
240
324
|
if (hasTransition()) {
|
|
241
325
|
popover.addEventListener('transitionend', () => {
|
|
@@ -248,7 +332,7 @@
|
|
|
248
332
|
|
|
249
333
|
popover.setAttribute('aria-hidden', 'false');
|
|
250
334
|
trigger.setAttribute('aria-expanded', 'true');
|
|
251
|
-
|
|
335
|
+
|
|
252
336
|
const selectedOption = listbox.querySelector('[role="option"][aria-selected="true"]');
|
|
253
337
|
if (selectedOption) {
|
|
254
338
|
setActiveOption(options.indexOf(selectedOption));
|
|
@@ -267,8 +351,24 @@
|
|
|
267
351
|
|
|
268
352
|
listbox.addEventListener('click', (event) => {
|
|
269
353
|
const clickedOption = event.target.closest('[role="option"]');
|
|
270
|
-
if (clickedOption)
|
|
271
|
-
|
|
354
|
+
if (!clickedOption) return;
|
|
355
|
+
|
|
356
|
+
const option = options.find(opt => opt === clickedOption);
|
|
357
|
+
if (!option) return;
|
|
358
|
+
|
|
359
|
+
if (isMultiple) {
|
|
360
|
+
toggleMultipleValue(option);
|
|
361
|
+
setActiveOption(options.indexOf(option));
|
|
362
|
+
if (filter) {
|
|
363
|
+
filter.focus();
|
|
364
|
+
} else {
|
|
365
|
+
trigger.focus();
|
|
366
|
+
}
|
|
367
|
+
} else {
|
|
368
|
+
if (input.value !== getValue(option)) {
|
|
369
|
+
updateValue(option);
|
|
370
|
+
}
|
|
371
|
+
closePopover();
|
|
272
372
|
}
|
|
273
373
|
});
|
|
274
374
|
|
|
@@ -285,8 +385,43 @@
|
|
|
285
385
|
});
|
|
286
386
|
|
|
287
387
|
popover.setAttribute('aria-hidden', 'true');
|
|
288
|
-
|
|
289
|
-
|
|
388
|
+
|
|
389
|
+
// Public API
|
|
390
|
+
Object.defineProperty(selectComponent, 'value', {
|
|
391
|
+
get: () => {
|
|
392
|
+
if (isMultiple) {
|
|
393
|
+
return options.filter(opt => selectedOptions.has(opt)).map(getValue);
|
|
394
|
+
} else {
|
|
395
|
+
return input.value;
|
|
396
|
+
}
|
|
397
|
+
},
|
|
398
|
+
set: (val) => {
|
|
399
|
+
if (isMultiple) {
|
|
400
|
+
const values = Array.isArray(val) ? val : (val != null ? [val] : []);
|
|
401
|
+
const opts = [];
|
|
402
|
+
values.forEach(v => {
|
|
403
|
+
const opt = options.find(o => getValue(o) === v && !opts.includes(o));
|
|
404
|
+
if (opt) opts.push(opt);
|
|
405
|
+
});
|
|
406
|
+
updateValue(opts);
|
|
407
|
+
} else {
|
|
408
|
+
const option = options.find(opt => getValue(opt) === val);
|
|
409
|
+
if (option) {
|
|
410
|
+
updateValue(option);
|
|
411
|
+
closePopover();
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
selectComponent.select = select;
|
|
418
|
+
selectComponent.selectByValue = select; // Backward compatibility alias
|
|
419
|
+
if (isMultiple) {
|
|
420
|
+
selectComponent.deselect = deselect;
|
|
421
|
+
selectComponent.toggle = toggle;
|
|
422
|
+
selectComponent.selectAll = () => updateValue(options);
|
|
423
|
+
selectComponent.selectNone = () => updateValue([]);
|
|
424
|
+
}
|
|
290
425
|
selectComponent.dataset.selectInitialized = true;
|
|
291
426
|
selectComponent.dispatchEvent(new CustomEvent('basecoat:initialized'));
|
|
292
427
|
};
|