basecoat-css 0.2.2 → 0.2.4

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