basecoat-css 0.2.8 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/js/all.js CHANGED
@@ -1,3 +1,102 @@
1
+ (() => {
2
+ const componentRegistry = {};
3
+ let observer = null;
4
+
5
+ const registerComponent = (name, selector, initFunction) => {
6
+ componentRegistry[name] = {
7
+ selector,
8
+ init: initFunction
9
+ };
10
+ };
11
+
12
+ const initComponent = (element, componentName) => {
13
+ const component = componentRegistry[componentName];
14
+ if (!component) return;
15
+
16
+ try {
17
+ component.init(element);
18
+ } catch (error) {
19
+ console.error(`Failed to initialize ${componentName}:`, error);
20
+ }
21
+ };
22
+
23
+ const initAllComponents = () => {
24
+ Object.entries(componentRegistry).forEach(([name, { selector, init }]) => {
25
+ document.querySelectorAll(selector).forEach(init);
26
+ });
27
+ };
28
+
29
+ const initNewComponents = (node) => {
30
+ if (node.nodeType !== Node.ELEMENT_NODE) return;
31
+
32
+ Object.entries(componentRegistry).forEach(([name, { selector, init }]) => {
33
+ if (node.matches(selector)) {
34
+ init(node);
35
+ }
36
+ node.querySelectorAll(selector).forEach(init);
37
+ });
38
+ };
39
+
40
+ const startObserver = () => {
41
+ if (observer) return;
42
+
43
+ observer = new MutationObserver((mutations) => {
44
+ mutations.forEach((mutation) => {
45
+ mutation.addedNodes.forEach(initNewComponents);
46
+ });
47
+ });
48
+
49
+ observer.observe(document.body, { childList: true, subtree: true });
50
+ };
51
+
52
+ const stopObserver = () => {
53
+ if (observer) {
54
+ observer.disconnect();
55
+ observer = null;
56
+ }
57
+ };
58
+
59
+ const reinitComponent = (componentName) => {
60
+ const component = componentRegistry[componentName];
61
+ if (!component) {
62
+ console.warn(`Component '${componentName}' not found in registry`);
63
+ return;
64
+ }
65
+
66
+ // Clear initialization flag for this component
67
+ const flag = `data-${componentName}-initialized`;
68
+ document.querySelectorAll(`[${flag}]`).forEach(el => {
69
+ el.removeAttribute(flag);
70
+ });
71
+
72
+ document.querySelectorAll(component.selector).forEach(component.init);
73
+ };
74
+
75
+ const reinitAll = () => {
76
+ // Clear all initialization flags using the registry
77
+ Object.entries(componentRegistry).forEach(([name, { selector }]) => {
78
+ const flag = `data-${name}-initialized`;
79
+ document.querySelectorAll(`[${flag}]`).forEach(el => {
80
+ el.removeAttribute(flag);
81
+ });
82
+ });
83
+
84
+ initAllComponents();
85
+ };
86
+
87
+ window.basecoat = {
88
+ register: registerComponent,
89
+ init: reinitComponent,
90
+ initAll: reinitAll,
91
+ start: startObserver,
92
+ stop: stopObserver
93
+ };
94
+
95
+ document.addEventListener('DOMContentLoaded', () => {
96
+ initAllComponents();
97
+ startObserver();
98
+ });
99
+ })();
1
100
  (() => {
2
101
  const initDropdownMenu = (dropdownMenuComponent) => {
3
102
  const trigger = dropdownMenuComponent.querySelector(':scope > button');
@@ -165,21 +264,9 @@
165
264
  dropdownMenuComponent.dispatchEvent(new CustomEvent('basecoat:initialized'));
166
265
  };
167
266
 
168
- document.querySelectorAll('.dropdown-menu:not([data-dropdown-menu-initialized])').forEach(initDropdownMenu);
169
-
170
- const observer = new MutationObserver((mutations) => {
171
- mutations.forEach((mutation) => {
172
- mutation.addedNodes.forEach((node) => {
173
- if (node.nodeType !== Node.ELEMENT_NODE) return;
174
- if (node.matches('.dropdown-menu:not([data-dropdown-menu-initialized])')) {
175
- initDropdownMenu(node);
176
- }
177
- node.querySelectorAll('.dropdown-menu:not([data-dropdown-menu-initialized])').forEach(initDropdownMenu);
178
- });
179
- });
180
- });
181
-
182
- observer.observe(document.body, { childList: true, subtree: true });
267
+ if (window.basecoat) {
268
+ window.basecoat.register('dropdown-menu', '.dropdown-menu:not([data-dropdown-menu-initialized])', initDropdownMenu);
269
+ }
183
270
  })();
184
271
  (() => {
185
272
  const initPopover = (popoverComponent) => {
@@ -250,21 +337,9 @@
250
337
  popoverComponent.dispatchEvent(new CustomEvent('basecoat:initialized'));
251
338
  };
252
339
 
253
- document.querySelectorAll('.popover:not([data-popover-initialized])').forEach(initPopover);
254
-
255
- const observer = new MutationObserver((mutations) => {
256
- mutations.forEach((mutation) => {
257
- mutation.addedNodes.forEach((node) => {
258
- if (node.nodeType !== Node.ELEMENT_NODE) return;
259
- if (node.matches('.popover:not([data-popover-initialized])')) {
260
- initPopover(node);
261
- }
262
- node.querySelectorAll('.popover:not([data-popover-initialized])').forEach(initPopover);
263
- });
264
- });
265
- });
266
-
267
- observer.observe(document.body, { childList: true, subtree: true });
340
+ if (window.basecoat) {
341
+ window.basecoat.register('popover', '.popover:not([data-popover-initialized])', initPopover);
342
+ }
268
343
  })();
269
344
 
270
345
  (() => {
@@ -314,12 +389,20 @@
314
389
  return parseFloat(style.transitionDuration) > 0 || parseFloat(style.transitionDelay) > 0;
315
390
  };
316
391
 
317
- const updateValue = (option) => {
392
+ const updateValue = (option, triggerEvent = true) => {
318
393
  if (option) {
319
394
  selectedLabel.innerHTML = option.dataset.label || option.innerHTML;
320
395
  input.value = option.dataset.value;
321
396
  listbox.querySelector('[role="option"][aria-selected="true"]')?.removeAttribute('aria-selected');
322
397
  option.setAttribute('aria-selected', 'true');
398
+
399
+ if (triggerEvent) {
400
+ const event = new CustomEvent('change', {
401
+ detail: { value: option.dataset.value },
402
+ bubbles: true
403
+ });
404
+ selectComponent.dispatchEvent(event);
405
+ }
323
406
  }
324
407
  };
325
408
 
@@ -357,14 +440,6 @@
357
440
  }
358
441
 
359
442
  closePopover();
360
-
361
- if (newValue !== oldValue) {
362
- const event = new CustomEvent('change', {
363
- detail: { value: newValue },
364
- bubbles: true
365
- });
366
- selectComponent.dispatchEvent(event);
367
- }
368
443
  };
369
444
 
370
445
  const selectByValue = (value) => {
@@ -395,7 +470,7 @@
395
470
  let initialOption = options.find(opt => opt.dataset.value === input.value);
396
471
  if (!initialOption && options.length > 0) initialOption = options[0];
397
472
 
398
- updateValue(initialOption);
473
+ updateValue(initialOption, false);
399
474
 
400
475
  const handleKeyNavigation = (event) => {
401
476
  const isPopoverOpen = popover.getAttribute('aria-hidden') === 'false';
@@ -543,22 +618,9 @@
543
618
  selectComponent.dispatchEvent(new CustomEvent('basecoat:initialized'));
544
619
  };
545
620
 
546
- document.querySelectorAll('div.select:not([data-select-initialized])').forEach(initSelect);
547
-
548
- const observer = new MutationObserver((mutations) => {
549
- mutations.forEach((mutation) => {
550
- mutation.addedNodes.forEach((node) => {
551
- if (node.nodeType === Node.ELEMENT_NODE) {
552
- if (node.matches('div.select:not([data-select-initialized])')) {
553
- initSelect(node);
554
- }
555
- node.querySelectorAll('div.select:not([data-select-initialized])').forEach(initSelect);
556
- }
557
- });
558
- });
559
- });
560
-
561
- observer.observe(document.body, { childList: true, subtree: true });
621
+ if (window.basecoat) {
622
+ window.basecoat.register('select', 'div.select:not([data-select-initialized])', initSelect);
623
+ }
562
624
  })();
563
625
  (() => {
564
626
  // Monkey patching the history API to detect client-side navigation
@@ -660,22 +722,9 @@
660
722
  sidebarComponent.dispatchEvent(new CustomEvent('basecoat:initialized'));
661
723
  };
662
724
 
663
- document.querySelectorAll('.sidebar:not([data-sidebar-initialized])').forEach(initSidebar);
664
-
665
- const observer = new MutationObserver((mutations) => {
666
- mutations.forEach((mutation) => {
667
- mutation.addedNodes.forEach((node) => {
668
- if (node.nodeType === Node.ELEMENT_NODE) {
669
- if (node.matches('.sidebar:not([data-sidebar-initialized])')) {
670
- initSidebar(node);
671
- }
672
- node.querySelectorAll('.sidebar:not([data-sidebar-initialized])').forEach(initSidebar);
673
- }
674
- });
675
- });
676
- });
677
-
678
- observer.observe(document.body, { childList: true, subtree: true });
725
+ if (window.basecoat) {
726
+ window.basecoat.register('sidebar', '.sidebar:not([data-sidebar-initialized])', initSidebar);
727
+ }
679
728
  })();
680
729
  (() => {
681
730
  const initTabs = (tabsComponent) => {
@@ -736,22 +785,9 @@
736
785
  tabsComponent.dispatchEvent(new CustomEvent('basecoat:initialized'));
737
786
  };
738
787
 
739
- document.querySelectorAll('.tabs:not([data-tabs-initialized])').forEach(initTabs);
740
-
741
- const observer = new MutationObserver((mutations) => {
742
- mutations.forEach((mutation) => {
743
- mutation.addedNodes.forEach((node) => {
744
- if (node.nodeType === Node.ELEMENT_NODE) {
745
- if (node.matches('.tabs:not([data-tabs-initialized])')) {
746
- initTabs(node);
747
- }
748
- node.querySelectorAll('.tabs:not([data-tabs-initialized])').forEach(initTabs);
749
- }
750
- });
751
- });
752
- });
753
-
754
- observer.observe(document.body, { childList: true, subtree: true });
788
+ if (window.basecoat) {
789
+ window.basecoat.register('tabs', '.tabs:not([data-tabs-initialized])', initTabs);
790
+ }
755
791
  })();
756
792
  (() => {
757
793
  let toaster;
@@ -919,9 +955,6 @@
919
955
  return template.content.firstChild;
920
956
  }
921
957
 
922
- const initialToaster = document.getElementById('toaster');
923
- if (initialToaster) initToaster(initialToaster);
924
-
925
958
  document.addEventListener('basecoat:toast', (event) => {
926
959
  if (!toaster) {
927
960
  console.error('Cannot create toast: toaster container not found on page.');
@@ -932,21 +965,8 @@
932
965
  toaster.appendChild(toastElement);
933
966
  });
934
967
 
935
- const observer = new MutationObserver((mutations) => {
936
- mutations.forEach((mutation) => {
937
- mutation.addedNodes.forEach((node) => {
938
- if (node.nodeType !== Node.ELEMENT_NODE) return;
939
-
940
- if (node.matches('#toaster')) {
941
- initToaster(node);
942
- }
943
-
944
- if (toaster && node.matches('.toast:not([data-toast-initialized])')) {
945
- initToast(node);
946
- }
947
- });
948
- });
949
- });
950
-
951
- observer.observe(document.body, { childList: true, subtree: true });
968
+ if (window.basecoat) {
969
+ window.basecoat.register('toaster', '#toaster:not([data-toaster-initialized])', initToaster);
970
+ window.basecoat.register('toast', '.toast:not([data-toast-initialized])', initToast);
971
+ }
952
972
  })();
@@ -1 +1 @@
1
- (()=>{const e=e=>{const t=e.querySelector(":scope > button"),n=e.querySelector(":scope > [data-popover]"),a=n.querySelector('[role="menu"]');if(!t||!a||!n){const i=[];return t||i.push("trigger"),a||i.push("menu"),n||i.push("popover"),void console.error(`Dropdown menu initialisation failed. Missing element(s): ${i.join(", ")}`,e)}let i=[],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"),i=Array.from(a.querySelectorAll('[role^="menuitem"]')).filter((e=>!e.hasAttribute("disabled")&&"true"!==e.getAttribute("aria-disabled"))),i.length>0&&o&&("first"===o?d(0):"last"===o&&d(i.length-1))},d=e=>{if(o>-1&&i[o]&&i[o].classList.remove("active"),o=e,o>-1&&i[o]){const e=i[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===i.length)return;let a=o;switch(e.key){case"ArrowDown":e.preventDefault(),a=-1===o?0:Math.min(o+1,i.length-1);break;case"ArrowUp":e.preventDefault(),a=-1===o?i.length-1:Math.max(o-1,0);break;case"Home":e.preventDefault(),a=0;break;case"End":e.preventDefault(),a=i.length-1;break;case"Enter":case" ":return e.preventDefault(),i[o]?.click(),void r()}a!==o&&d(a)})),a.addEventListener("mousemove",(e=>{const t=e.target.closest('[role^="menuitem"]');if(t&&i.includes(t)){const e=i.indexOf(t);e!==o&&d(e)}})),a.addEventListener("mouseleave",(()=>{d(-1)})),a.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"))};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"),n=e.querySelector(":scope > [data-popover]");if(!t||!n){const a=[];return t||a.push("trigger"),n||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"),n.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=n.querySelector("[autofocus]");a&&n.addEventListener("transitionend",(()=>{a.focus()}),{once:!0}),t.setAttribute("aria-expanded","true"),n.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,e.dispatchEvent(new CustomEvent("basecoat:initialized"))};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"),n=t.querySelector(":scope > span"),a=e.querySelector(":scope > [data-popover]"),i=a.querySelector('[role="listbox"]'),o=e.querySelector(':scope > input[type="hidden"]'),r=e.querySelector('header input[type="text"]');if(!(t&&a&&i&&o)){const n=[];return t||n.push("trigger"),a||n.push("popover"),i||n.push("listbox"),o||n.push("input"),void console.error(`Select component initialisation failed. Missing element(s): ${n.join(", ")}`,e)}const s=Array.from(i.querySelectorAll('[role="option"]'));let d=[...s],c=-1;const l=e=>{if(c>-1&&s[c]&&s[c].classList.remove("active"),c=e,c>-1){const e=s[c];e.classList.add("active"),e.id?t.setAttribute("aria-activedescendant",e.id):t.removeAttribute("aria-activedescendant")}else t.removeAttribute("aria-activedescendant")},u=()=>{const e=getComputedStyle(a);return parseFloat(e.transitionDuration)>0||parseFloat(e.transitionDelay)>0},p=e=>{e&&(n.innerHTML=e.dataset.label||e.innerHTML,o.value=e.dataset.value,i.querySelector('[role="option"][aria-selected="true"]')?.removeAttribute("aria-selected"),e.setAttribute("aria-selected","true"))},v=(e=!0)=>{if("true"!==a.getAttribute("aria-hidden")){if(r){const e=()=>{r.value="",d=[...s],s.forEach((e=>e.setAttribute("aria-hidden","false")))};u()?a.addEventListener("transitionend",e,{once:!0}):e()}e&&t.focus(),a.setAttribute("aria-hidden","true"),t.setAttribute("aria-expanded","false"),l(-1)}},h=t=>{if(!t)return;const n=o.value,a=t.dataset.value;if(null!=a&&a!==n&&p(t),v(),a!==n){const t=new CustomEvent("change",{detail:{value:a},bubbles:!0});e.dispatchEvent(t)}};if(r){const e=()=>{const e=r.value.trim().toLowerCase();l(-1),d=[],s.forEach((t=>{const n=(t.dataset.label||t.textContent).trim().toLowerCase().includes(e);t.setAttribute("aria-hidden",String(!n)),n&&d.push(t)}))};r.addEventListener("input",e)}let b=s.find((e=>e.dataset.value===o.value));!b&&s.length>0&&(b=s[0]),p(b);const m=e=>{const n="false"===a.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 v();if("Enter"===e.key)return void(c>-1&&h(s[c]));if(0===d.length)return;const i=c>-1?d.indexOf(s[c]):-1;let o=i;switch(e.key){case"ArrowDown":i<d.length-1&&(o=i+1);break;case"ArrowUp":i>0?o=i-1:-1===i&&(o=0);break;case"Home":o=0;break;case"End":o=d.length-1}if(o!==i){const e=d[o];l(s.indexOf(e)),e.scrollIntoView({block:"nearest",behavior:"smooth"})}};i.addEventListener("mousemove",(e=>{const t=e.target.closest('[role="option"]');if(t&&d.includes(t)){const e=s.indexOf(t);e!==c&&l(e)}})),i.addEventListener("mouseleave",(()=>{const e=i.querySelector('[role="option"][aria-selected="true"]');l(e?s.indexOf(e):-1)})),t.addEventListener("keydown",m),r&&r.addEventListener("keydown",m);t.addEventListener("click",(()=>{"true"===t.getAttribute("aria-expanded")?v():(()=>{document.dispatchEvent(new CustomEvent("basecoat:popover",{detail:{source:e}})),r&&(u()?a.addEventListener("transitionend",(()=>{r.focus()}),{once:!0}):r.focus()),a.setAttribute("aria-hidden","false"),t.setAttribute("aria-expanded","true");const n=i.querySelector('[role="option"][aria-selected="true"]');n&&(l(s.indexOf(n)),n.scrollIntoView({block:"nearest"}))})()})),i.addEventListener("click",(e=>{const t=e.target.closest('[role="option"]');t&&h(t)})),document.addEventListener("click",(t=>{e.contains(t.target)||v(!1)})),document.addEventListener("basecoat:popover",(t=>{t.detail.source!==e&&v(!1)})),a.setAttribute("aria-hidden","true"),e.selectByValue=e=>{const t=s.find((t=>t.dataset.value===e));h(t)},e.dataset.selectInitialized=!0,e.dispatchEvent(new CustomEvent("basecoat:initialized"))};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,n="true"===e.dataset.initialMobileOpen,a=parseInt(e.dataset.breakpoint)||768;let i=a>0?window.innerWidth>=a?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",!i),i?e.removeAttribute("inert"):e.setAttribute("inert","")},s=e=>{i=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(!i)}})),e.addEventListener("click",(t=>{const n=t.target,i=e.querySelector("nav");if(window.innerWidth<a&&n.closest("a, button")&&!n.closest("[data-keep-mobile-sidebar-open]"))return document.activeElement&&document.activeElement.blur(),void s(!1);(n===e||i&&!i.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"))};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 n=Array.from(t.querySelectorAll('[role="tab"]')),a=n.map((e=>document.getElementById(e.getAttribute("aria-controls")))).filter(Boolean),i=e=>{n.forEach(((e,t)=>{e.setAttribute("aria-selected","false"),e.setAttribute("tabindex","-1"),a[t]&&(a[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&&i(t)})),t.addEventListener("keydown",(e=>{const t=e.target;if(!n.includes(t))return;let a;const o=n.indexOf(t);switch(e.key){case"ArrowRight":a=n[(o+1)%n.length];break;case"ArrowLeft":a=n[(o-1+n.length)%n.length];break;case"Home":a=n[0];break;case"End":a=n[n.length-1];break;default:return}e.preventDefault(),i(a),a.focus()})),e.dataset.tabsInitialized=!0,e.dispatchEvent(new CustomEvent("basecoat:initialized"))};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 n=!1;const a={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 i(t){t.dataset.toasterInitialized||(e=t,e.addEventListener("mouseenter",r),e.addEventListener("mouseleave",s),e.addEventListener("click",(e=>{const t=e.target.closest(".toast footer a"),n=e.target.closest(".toast footer button");(t||n)&&d(e.target.closest(".toast"))})),e.querySelectorAll(".toast:not([data-toast-initialized])").forEach(o),e.dataset.toasterInitialized="true",e.dispatchEvent(new CustomEvent("basecoat:initialized")))}function o(e){if(e.dataset.toastInitialized)return;const a=parseInt(e.dataset.duration),i=-1!==a?a||("error"===e.dataset.category?5e3:3e3):-1,o={remainingTime:i,timeoutId:null,startTime:null};-1!==i&&(n?o.timeoutId=null:(o.startTime=Date.now(),o.timeoutId=setTimeout((()=>d(e)),i))),t.set(e,o),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 s(){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((()=>d(e)),n.remainingTime)):d(e))})))}function d(e){if(!t.has(e))return;const n=t.get(e);clearTimeout(n.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&&i(c),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:i,action:o,cancel:r,duration:s,icon:d}=e,c=d||t&&a[t]||"",l=n?`<h2>${n}</h2>`:"",u=i?`<p>${i}</p>`:"",p=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>`:"",v=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>`:"",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 `,b=document.createElement("template");return b.innerHTML=h.trim(),b.content.firstChild}(t.detail?.config||{});e.appendChild(n)}));new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches("#toaster")&&i(t),e&&t.matches(".toast:not([data-toast-initialized])")&&o(t))}))}))})).observe(document.body,{childList:!0,subtree:!0})})();
1
+ (()=>{const e={};let t=null;const n=()=>{Object.entries(e).forEach((([e,{selector:t,init:n}])=>{document.querySelectorAll(t).forEach(n)}))},a=t=>{t.nodeType===Node.ELEMENT_NODE&&Object.entries(e).forEach((([e,{selector:n,init:a}])=>{t.matches(n)&&a(t),t.querySelectorAll(n).forEach(a)}))},i=()=>{t||(t=new MutationObserver((e=>{e.forEach((e=>{e.addedNodes.forEach(a)}))})),t.observe(document.body,{childList:!0,subtree:!0}))};window.basecoat={register:(t,n,a)=>{e[t]={selector:n,init:a}},init:t=>{const n=e[t];if(!n)return void console.warn(`Component '${t}' not found in registry`);const a=`data-${t}-initialized`;document.querySelectorAll(`[${a}]`).forEach((e=>{e.removeAttribute(a)})),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:i,stop:()=>{t&&(t.disconnect(),t=null)}},document.addEventListener("DOMContentLoaded",(()=>{n(),i()}))})(),(()=>{const e=e=>{const t=e.querySelector(":scope > button"),n=e.querySelector(":scope > [data-popover]"),a=n.querySelector('[role="menu"]');if(!t||!a||!n){const i=[];return t||i.push("trigger"),a||i.push("menu"),n||i.push("popover"),void console.error(`Dropdown menu initialisation failed. Missing element(s): ${i.join(", ")}`,e)}let i=[],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"),i=Array.from(a.querySelectorAll('[role^="menuitem"]')).filter((e=>!e.hasAttribute("disabled")&&"true"!==e.getAttribute("aria-disabled"))),i.length>0&&o&&("first"===o?d(0):"last"===o&&d(i.length-1))},d=e=>{if(o>-1&&i[o]&&i[o].classList.remove("active"),o=e,o>-1&&i[o]){const e=i[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===i.length)return;let a=o;switch(e.key){case"ArrowDown":e.preventDefault(),a=-1===o?0:Math.min(o+1,i.length-1);break;case"ArrowUp":e.preventDefault(),a=-1===o?i.length-1:Math.max(o-1,0);break;case"Home":e.preventDefault(),a=0;break;case"End":e.preventDefault(),a=i.length-1;break;case"Enter":case" ":return e.preventDefault(),i[o]?.click(),void r()}a!==o&&d(a)})),a.addEventListener("mousemove",(e=>{const t=e.target.closest('[role^="menuitem"]');if(t&&i.includes(t)){const e=i.indexOf(t);e!==o&&d(e)}})),a.addEventListener("mouseleave",(()=>{d(-1)})),a.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 a=[];return t||a.push("trigger"),n||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"),n.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=n.querySelector("[autofocus]");a&&n.addEventListener("transitionend",(()=>{a.focus()}),{once:!0}),t.setAttribute("aria-expanded","true"),n.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,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"),a=e.querySelector(":scope > [data-popover]"),i=a.querySelector('[role="listbox"]'),o=e.querySelector(':scope > input[type="hidden"]'),r=e.querySelector('header input[type="text"]');if(!(t&&a&&i&&o)){const n=[];return t||n.push("trigger"),a||n.push("popover"),i||n.push("listbox"),o||n.push("input"),void console.error(`Select component initialisation failed. Missing element(s): ${n.join(", ")}`,e)}const s=Array.from(i.querySelectorAll('[role="option"]'));let d=[...s],c=-1;const l=e=>{if(c>-1&&s[c]&&s[c].classList.remove("active"),c=e,c>-1){const e=s[c];e.classList.add("active"),e.id?t.setAttribute("aria-activedescendant",e.id):t.removeAttribute("aria-activedescendant")}else t.removeAttribute("aria-activedescendant")},u=()=>{const e=getComputedStyle(a);return parseFloat(e.transitionDuration)>0||parseFloat(e.transitionDelay)>0},v=(t,a=!0)=>{if(t&&(n.innerHTML=t.dataset.label||t.innerHTML,o.value=t.dataset.value,i.querySelector('[role="option"][aria-selected="true"]')?.removeAttribute("aria-selected"),t.setAttribute("aria-selected","true"),a)){const n=new CustomEvent("change",{detail:{value:t.dataset.value},bubbles:!0});e.dispatchEvent(n)}},p=(e=!0)=>{if("true"!==a.getAttribute("aria-hidden")){if(r){const e=()=>{r.value="",d=[...s],s.forEach((e=>e.setAttribute("aria-hidden","false")))};u()?a.addEventListener("transitionend",e,{once:!0}):e()}e&&t.focus(),a.setAttribute("aria-hidden","true"),t.setAttribute("aria-expanded","false"),l(-1)}},h=e=>{if(!e)return;const t=o.value,n=e.dataset.value;null!=n&&n!==t&&v(e),p()};if(r){const e=()=>{const e=r.value.trim().toLowerCase();l(-1),d=[],s.forEach((t=>{const n=(t.dataset.label||t.textContent).trim().toLowerCase().includes(e);t.setAttribute("aria-hidden",String(!n)),n&&d.push(t)}))};r.addEventListener("input",e)}let b=s.find((e=>e.dataset.value===o.value));!b&&s.length>0&&(b=s[0]),v(b,!1);const m=e=>{const n="false"===a.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 p();if("Enter"===e.key)return void(c>-1&&h(s[c]));if(0===d.length)return;const i=c>-1?d.indexOf(s[c]):-1;let o=i;switch(e.key){case"ArrowDown":i<d.length-1&&(o=i+1);break;case"ArrowUp":i>0?o=i-1:-1===i&&(o=0);break;case"Home":o=0;break;case"End":o=d.length-1}if(o!==i){const e=d[o];l(s.indexOf(e)),e.scrollIntoView({block:"nearest",behavior:"smooth"})}};i.addEventListener("mousemove",(e=>{const t=e.target.closest('[role="option"]');if(t&&d.includes(t)){const e=s.indexOf(t);e!==c&&l(e)}})),i.addEventListener("mouseleave",(()=>{const e=i.querySelector('[role="option"][aria-selected="true"]');l(e?s.indexOf(e):-1)})),t.addEventListener("keydown",m),r&&r.addEventListener("keydown",m);t.addEventListener("click",(()=>{"true"===t.getAttribute("aria-expanded")?p():(()=>{document.dispatchEvent(new CustomEvent("basecoat:popover",{detail:{source:e}})),r&&(u()?a.addEventListener("transitionend",(()=>{r.focus()}),{once:!0}):r.focus()),a.setAttribute("aria-hidden","false"),t.setAttribute("aria-expanded","true");const n=i.querySelector('[role="option"][aria-selected="true"]');n&&(l(s.indexOf(n)),n.scrollIntoView({block:"nearest"}))})()})),i.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)})),a.setAttribute("aria-hidden","true"),e.selectByValue=e=>{const t=s.find((t=>t.dataset.value===e));h(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,a=parseInt(e.dataset.breakpoint)||768;let i=a>0?window.innerWidth>=a?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",!i),i?e.removeAttribute("inert"):e.setAttribute("inert","")},s=e=>{i=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(!i)}})),e.addEventListener("click",(t=>{const n=t.target,i=e.querySelector("nav");if(window.innerWidth<a&&n.closest("a, button")&&!n.closest("[data-keep-mobile-sidebar-open]"))return document.activeElement&&document.activeElement.blur(),void s(!1);(n===e||i&&!i.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"]')),a=n.map((e=>document.getElementById(e.getAttribute("aria-controls")))).filter(Boolean),i=e=>{n.forEach(((e,t)=>{e.setAttribute("aria-selected","false"),e.setAttribute("tabindex","-1"),a[t]&&(a[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&&i(t)})),t.addEventListener("keydown",(e=>{const t=e.target;if(!n.includes(t))return;let a;const o=n.indexOf(t);switch(e.key){case"ArrowRight":a=n[(o+1)%n.length];break;case"ArrowLeft":a=n[(o-1+n.length)%n.length];break;case"Home":a=n[0];break;case"End":a=n[n.length-1];break;default:return}e.preventDefault(),i(a),a.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 a={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 i(e){if(e.dataset.toastInitialized)return;const a=parseInt(e.dataset.duration),i=-1!==a?a||("error"===e.dataset.category?5e3:3e3):-1,o={remainingTime:i,timeoutId:null,startTime:null};-1!==i&&(n?o.timeoutId=null:(o.startTime=Date.now(),o.timeoutId=setTimeout((()=>s(e)),i))),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),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:i,action:o,cancel:r,duration:s,icon:d}=e,c=d||t&&a[t]||"",l=n?`<h2>${n}</h2>`:"",u=i?`<p>${i}</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>`:"",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 ${v||p?`<footer>${v}${p}</footer>`:""}\n </div>\n </div>\n </div>\n `,b=document.createElement("template");return b.innerHTML=h.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(i),e.dataset.toasterInitialized="true",e.dispatchEvent(new CustomEvent("basecoat:initialized")))})),window.basecoat.register("toast",".toast:not([data-toast-initialized])",i))})();
@@ -0,0 +1,99 @@
1
+ (() => {
2
+ const componentRegistry = {};
3
+ let observer = null;
4
+
5
+ const registerComponent = (name, selector, initFunction) => {
6
+ componentRegistry[name] = {
7
+ selector,
8
+ init: initFunction
9
+ };
10
+ };
11
+
12
+ const initComponent = (element, componentName) => {
13
+ const component = componentRegistry[componentName];
14
+ if (!component) return;
15
+
16
+ try {
17
+ component.init(element);
18
+ } catch (error) {
19
+ console.error(`Failed to initialize ${componentName}:`, error);
20
+ }
21
+ };
22
+
23
+ const initAllComponents = () => {
24
+ Object.entries(componentRegistry).forEach(([name, { selector, init }]) => {
25
+ document.querySelectorAll(selector).forEach(init);
26
+ });
27
+ };
28
+
29
+ const initNewComponents = (node) => {
30
+ if (node.nodeType !== Node.ELEMENT_NODE) return;
31
+
32
+ Object.entries(componentRegistry).forEach(([name, { selector, init }]) => {
33
+ if (node.matches(selector)) {
34
+ init(node);
35
+ }
36
+ node.querySelectorAll(selector).forEach(init);
37
+ });
38
+ };
39
+
40
+ const startObserver = () => {
41
+ if (observer) return;
42
+
43
+ observer = new MutationObserver((mutations) => {
44
+ mutations.forEach((mutation) => {
45
+ mutation.addedNodes.forEach(initNewComponents);
46
+ });
47
+ });
48
+
49
+ observer.observe(document.body, { childList: true, subtree: true });
50
+ };
51
+
52
+ const stopObserver = () => {
53
+ if (observer) {
54
+ observer.disconnect();
55
+ observer = null;
56
+ }
57
+ };
58
+
59
+ const reinitComponent = (componentName) => {
60
+ const component = componentRegistry[componentName];
61
+ if (!component) {
62
+ console.warn(`Component '${componentName}' not found in registry`);
63
+ return;
64
+ }
65
+
66
+ // Clear initialization flag for this component
67
+ const flag = `data-${componentName}-initialized`;
68
+ document.querySelectorAll(`[${flag}]`).forEach(el => {
69
+ el.removeAttribute(flag);
70
+ });
71
+
72
+ document.querySelectorAll(component.selector).forEach(component.init);
73
+ };
74
+
75
+ const reinitAll = () => {
76
+ // Clear all initialization flags using the registry
77
+ Object.entries(componentRegistry).forEach(([name, { selector }]) => {
78
+ const flag = `data-${name}-initialized`;
79
+ document.querySelectorAll(`[${flag}]`).forEach(el => {
80
+ el.removeAttribute(flag);
81
+ });
82
+ });
83
+
84
+ initAllComponents();
85
+ };
86
+
87
+ window.basecoat = {
88
+ register: registerComponent,
89
+ init: reinitComponent,
90
+ initAll: reinitAll,
91
+ start: startObserver,
92
+ stop: stopObserver
93
+ };
94
+
95
+ document.addEventListener('DOMContentLoaded', () => {
96
+ initAllComponents();
97
+ startObserver();
98
+ });
99
+ })();
@@ -0,0 +1 @@
1
+ (()=>{const e={};let t=null;const o=()=>{Object.entries(e).forEach((([e,{selector:t,init:o}])=>{document.querySelectorAll(t).forEach(o)}))},r=t=>{t.nodeType===Node.ELEMENT_NODE&&Object.entries(e).forEach((([e,{selector:o,init:r}])=>{t.matches(o)&&r(t),t.querySelectorAll(o).forEach(r)}))},n=()=>{t||(t=new MutationObserver((e=>{e.forEach((e=>{e.addedNodes.forEach(r)}))})),t.observe(document.body,{childList:!0,subtree:!0}))};window.basecoat={register:(t,o,r)=>{e[t]={selector:o,init:r}},init:t=>{const o=e[t];if(!o)return void console.warn(`Component '${t}' not found in registry`);const r=`data-${t}-initialized`;document.querySelectorAll(`[${r}]`).forEach((e=>{e.removeAttribute(r)})),document.querySelectorAll(o.selector).forEach(o.init)},initAll:()=>{Object.entries(e).forEach((([e,{selector:t}])=>{const o=`data-${e}-initialized`;document.querySelectorAll(`[${o}]`).forEach((e=>{e.removeAttribute(o)}))})),o()},start:n,stop:()=>{t&&(t.disconnect(),t=null)}},document.addEventListener("DOMContentLoaded",(()=>{o(),n()}))})();
@@ -165,19 +165,7 @@
165
165
  dropdownMenuComponent.dispatchEvent(new CustomEvent('basecoat:initialized'));
166
166
  };
167
167
 
168
- document.querySelectorAll('.dropdown-menu:not([data-dropdown-menu-initialized])').forEach(initDropdownMenu);
169
-
170
- const observer = new MutationObserver((mutations) => {
171
- mutations.forEach((mutation) => {
172
- mutation.addedNodes.forEach((node) => {
173
- if (node.nodeType !== Node.ELEMENT_NODE) return;
174
- if (node.matches('.dropdown-menu:not([data-dropdown-menu-initialized])')) {
175
- initDropdownMenu(node);
176
- }
177
- node.querySelectorAll('.dropdown-menu:not([data-dropdown-menu-initialized])').forEach(initDropdownMenu);
178
- });
179
- });
180
- });
181
-
182
- observer.observe(document.body, { childList: true, subtree: true });
168
+ if (window.basecoat) {
169
+ window.basecoat.register('dropdown-menu', '.dropdown-menu:not([data-dropdown-menu-initialized])', initDropdownMenu);
170
+ }
183
171
  })();
@@ -1 +1 @@
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=(i=!1)=>{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&&i&&("first"===i?s(0):"last"===i&&s(n.length-1))},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(!1)})),e.addEventListener("keydown",(e=>{const r="true"===t.getAttribute("aria-expanded");if("Escape"===e.key)return void(r&&o());if(!r)return void(["Enter"," "].includes(e.key)?(e.preventDefault(),d(!1)):"ArrowDown"===e.key?(e.preventDefault(),d("first")):"ArrowUp"===e.key&&(e.preventDefault(),d("last")));if(0===n.length)return;let a=i;switch(e.key){case"ArrowDown":e.preventDefault(),a=-1===i?0:Math.min(i+1,n.length-1);break;case"ArrowUp":e.preventDefault(),a=-1===i?n.length-1: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("mousemove",(e=>{const t=e.target.closest('[role^="menuitem"]');if(t&&n.includes(t)){const e=n.indexOf(t);e!==i&&s(e)}})),a.addEventListener("mouseleave",(()=>{s(-1)})),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,e.dispatchEvent(new CustomEvent("basecoat:initialized"))};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})})();
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 s=(e=!0)=>{"false"!==t.getAttribute("aria-expanded")&&(t.setAttribute("aria-expanded","false"),t.removeAttribute("aria-activedescendant"),r.setAttribute("aria-hidden","true"),e&&t.focus(),d(-1))},o=(i=!1)=>{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&&i&&("first"===i?d(0):"last"===i&&d(n.length-1))},d=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")?s():o(!1)})),e.addEventListener("keydown",(e=>{const r="true"===t.getAttribute("aria-expanded");if("Escape"===e.key)return void(r&&s());if(!r)return void(["Enter"," "].includes(e.key)?(e.preventDefault(),o(!1)):"ArrowDown"===e.key?(e.preventDefault(),o("first")):"ArrowUp"===e.key&&(e.preventDefault(),o("last")));if(0===n.length)return;let a=i;switch(e.key){case"ArrowDown":e.preventDefault(),a=-1===i?0:Math.min(i+1,n.length-1);break;case"ArrowUp":e.preventDefault(),a=-1===i?n.length-1: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 s()}a!==i&&d(a)})),a.addEventListener("mousemove",(e=>{const t=e.target.closest('[role^="menuitem"]');if(t&&n.includes(t)){const e=n.indexOf(t);e!==i&&d(e)}})),a.addEventListener("mouseleave",(()=>{d(-1)})),a.addEventListener("click",(e=>{e.target.closest('[role^="menuitem"]')&&s()})),document.addEventListener("click",(t=>{e.contains(t.target)||s()})),document.addEventListener("basecoat:popover",(t=>{t.detail.source!==e&&s(!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)})();
@@ -67,19 +67,7 @@
67
67
  popoverComponent.dispatchEvent(new CustomEvent('basecoat:initialized'));
68
68
  };
69
69
 
70
- document.querySelectorAll('.popover:not([data-popover-initialized])').forEach(initPopover);
71
-
72
- const observer = new MutationObserver((mutations) => {
73
- mutations.forEach((mutation) => {
74
- mutation.addedNodes.forEach((node) => {
75
- if (node.nodeType !== Node.ELEMENT_NODE) return;
76
- if (node.matches('.popover:not([data-popover-initialized])')) {
77
- initPopover(node);
78
- }
79
- node.querySelectorAll('.popover:not([data-popover-initialized])').forEach(initPopover);
80
- });
81
- });
82
- });
83
-
84
- observer.observe(document.body, { childList: true, subtree: true });
70
+ if (window.basecoat) {
71
+ window.basecoat.register('popover', '.popover:not([data-popover-initialized])', initPopover);
72
+ }
85
73
  })();
@@ -1 +1 @@
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,e.dispatchEvent(new CustomEvent("basecoat:initialized"))};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})})();
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,e.dispatchEvent(new CustomEvent("basecoat:initialized"))};window.basecoat&&window.basecoat.register("popover",".popover:not([data-popover-initialized])",e)})();
package/dist/js/select.js CHANGED
@@ -45,12 +45,20 @@
45
45
  return parseFloat(style.transitionDuration) > 0 || parseFloat(style.transitionDelay) > 0;
46
46
  };
47
47
 
48
- const updateValue = (option) => {
48
+ const updateValue = (option, triggerEvent = true) => {
49
49
  if (option) {
50
50
  selectedLabel.innerHTML = option.dataset.label || option.innerHTML;
51
51
  input.value = option.dataset.value;
52
52
  listbox.querySelector('[role="option"][aria-selected="true"]')?.removeAttribute('aria-selected');
53
53
  option.setAttribute('aria-selected', 'true');
54
+
55
+ if (triggerEvent) {
56
+ const event = new CustomEvent('change', {
57
+ detail: { value: option.dataset.value },
58
+ bubbles: true
59
+ });
60
+ selectComponent.dispatchEvent(event);
61
+ }
54
62
  }
55
63
  };
56
64
 
@@ -88,14 +96,6 @@
88
96
  }
89
97
 
90
98
  closePopover();
91
-
92
- if (newValue !== oldValue) {
93
- const event = new CustomEvent('change', {
94
- detail: { value: newValue },
95
- bubbles: true
96
- });
97
- selectComponent.dispatchEvent(event);
98
- }
99
99
  };
100
100
 
101
101
  const selectByValue = (value) => {
@@ -126,7 +126,7 @@
126
126
  let initialOption = options.find(opt => opt.dataset.value === input.value);
127
127
  if (!initialOption && options.length > 0) initialOption = options[0];
128
128
 
129
- updateValue(initialOption);
129
+ updateValue(initialOption, false);
130
130
 
131
131
  const handleKeyNavigation = (event) => {
132
132
  const isPopoverOpen = popover.getAttribute('aria-hidden') === 'false';
@@ -274,20 +274,7 @@
274
274
  selectComponent.dispatchEvent(new CustomEvent('basecoat:initialized'));
275
275
  };
276
276
 
277
- document.querySelectorAll('div.select:not([data-select-initialized])').forEach(initSelect);
278
-
279
- const observer = new MutationObserver((mutations) => {
280
- mutations.forEach((mutation) => {
281
- mutation.addedNodes.forEach((node) => {
282
- if (node.nodeType === Node.ELEMENT_NODE) {
283
- if (node.matches('div.select:not([data-select-initialized])')) {
284
- initSelect(node);
285
- }
286
- node.querySelectorAll('div.select:not([data-select-initialized])').forEach(initSelect);
287
- }
288
- });
289
- });
290
- });
291
-
292
- observer.observe(document.body, { childList: true, subtree: true });
277
+ if (window.basecoat) {
278
+ window.basecoat.register('select', 'div.select:not([data-select-initialized])', initSelect);
279
+ }
293
280
  })();