basecoat-cli 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/jinja/dialog.html.jinja +1 -1
- package/dist/assets/jinja/dropdown-menu.html.jinja +3 -3
- package/dist/assets/jinja/select.html.jinja +61 -49
- package/dist/assets/jinja/toast.html.jinja +2 -2
- package/dist/assets/js/all.js +796 -0
- package/dist/assets/js/all.min.js +1 -0
- package/dist/assets/js/dark-mode.js +10 -0
- package/dist/assets/js/dark-mode.min.js +1 -0
- package/dist/assets/js/dropdown-menu.js +128 -83
- package/dist/assets/js/dropdown-menu.min.js +1 -0
- package/dist/assets/js/popover.js +69 -26
- package/dist/assets/js/popover.min.js +1 -0
- package/dist/assets/js/select.js +195 -136
- package/dist/assets/js/select.min.js +1 -0
- package/dist/assets/js/sidebar.js +109 -24
- package/dist/assets/js/sidebar.min.js +1 -0
- package/dist/assets/js/tabs.js +68 -57
- package/dist/assets/js/tabs.min.js +1 -0
- package/dist/assets/js/toast.js +183 -62
- package/dist/assets/js/toast.min.js +1 -0
- package/dist/assets/nunjucks/dialog.njk +63 -79
- package/dist/assets/nunjucks/dropdown-menu.njk +29 -27
- package/dist/assets/nunjucks/popover.njk +11 -19
- package/dist/assets/nunjucks/select.njk +57 -37
- package/dist/assets/nunjucks/sidebar.njk +2 -5
- package/dist/assets/nunjucks/tabs.njk +7 -8
- package/dist/assets/nunjucks/toast.njk +45 -134
- package/dist/index.js +7 -7
- package/package.json +1 -1
- package/dist/assets/js/dialog.js +0 -54
package/dist/assets/js/select.js
CHANGED
|
@@ -1,150 +1,209 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
focusedIndex: null,
|
|
11
|
-
selectedLabel: null,
|
|
12
|
-
selectedValue: null,
|
|
13
|
-
query: '',
|
|
1
|
+
(() => {
|
|
2
|
+
const initSelect = (selectComponent) => {
|
|
3
|
+
const trigger = selectComponent.querySelector(':scope > button');
|
|
4
|
+
const selectedValue = trigger.querySelector(':scope > span');
|
|
5
|
+
const popover = selectComponent.querySelector(':scope > [data-popover]');
|
|
6
|
+
const listbox = popover.querySelector('[role="listbox"]');
|
|
7
|
+
const input = selectComponent.querySelector(':scope > input[type="hidden"]');
|
|
8
|
+
const filter = selectComponent.querySelector('header input[type="text"]');
|
|
9
|
+
if (!trigger || !popover || !listbox || !input) return;
|
|
14
10
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
} else if (this.focusedIndex < 0 || this.focusedIndex === null) {
|
|
36
|
-
this.focusedIndex = 0;
|
|
11
|
+
const options = Array.from(listbox.querySelectorAll('[role="option"]'));
|
|
12
|
+
let visibleOptions = [...options];
|
|
13
|
+
let activeIndex = -1;
|
|
14
|
+
|
|
15
|
+
const updateValue = (option) => {
|
|
16
|
+
if (option) {
|
|
17
|
+
selectedValue.innerHTML = option.dataset.label || option.innerHTML;
|
|
18
|
+
input.value = option.dataset.value;
|
|
19
|
+
listbox.querySelector('[role="option"][aria-selected="true"]')?.removeAttribute('aria-selected');
|
|
20
|
+
option.setAttribute('aria-selected', 'true');
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const closePopover = () => {
|
|
25
|
+
popover.setAttribute('aria-hidden', 'true');
|
|
26
|
+
trigger.setAttribute('aria-expanded', 'false');
|
|
27
|
+
if (filter) {
|
|
28
|
+
filter.value = '';
|
|
29
|
+
visibleOptions = [...options];
|
|
30
|
+
options.forEach(opt => opt.setAttribute('aria-hidden', 'false'));
|
|
37
31
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (this.options.length === 0 || this.selectedValue === null) return;
|
|
45
|
-
const option = this.options.find(opt => opt.getAttribute('data-value') === this.selectedValue);
|
|
32
|
+
trigger.removeAttribute('aria-activedescendant');
|
|
33
|
+
if (activeIndex > -1) options[activeIndex]?.classList.remove('active');
|
|
34
|
+
activeIndex = -1;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const selectOption = (option) => {
|
|
46
38
|
if (!option) return;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
39
|
+
|
|
40
|
+
if (option.dataset.value) {
|
|
41
|
+
updateValue(option);
|
|
42
|
+
}
|
|
43
|
+
closePopover();
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
if (filter) {
|
|
47
|
+
const filterOptions = () => {
|
|
48
|
+
const searchTerm = filter.value.trim().toLowerCase();
|
|
49
|
+
|
|
50
|
+
if (activeIndex > -1) {
|
|
51
|
+
options[activeIndex].classList.remove('active');
|
|
52
|
+
trigger.removeAttribute('aria-activedescendant');
|
|
53
|
+
activeIndex = -1;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
visibleOptions = [];
|
|
57
|
+
options.forEach(option => {
|
|
58
|
+
const optionText = (option.dataset.label || option.textContent).trim().toLowerCase();
|
|
59
|
+
const matches = optionText.includes(searchTerm);
|
|
60
|
+
option.setAttribute('aria-hidden', String(!matches));
|
|
61
|
+
if (matches) {
|
|
62
|
+
visibleOptions.push(option);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
filter.addEventListener('input', filterOptions);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
let initialOption = options.find(opt => input.value && opt.dataset.value === input.value);
|
|
71
|
+
if (!initialOption && options.length > 0) initialOption = options[0];
|
|
72
|
+
|
|
73
|
+
updateValue(initialOption);
|
|
74
|
+
|
|
75
|
+
const handleKeyNavigation = (e) => {
|
|
76
|
+
const isPopoverOpen = popover.getAttribute('aria-hidden') === 'false';
|
|
77
|
+
|
|
78
|
+
if (!['ArrowDown', 'ArrowUp', 'Enter', 'Home', 'End', 'Escape'].includes(e.key)) {
|
|
79
|
+
return;
|
|
60
80
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
this.$nextTick(() => this.$refs.trigger.focus());
|
|
81
|
+
|
|
82
|
+
if (!isPopoverOpen) {
|
|
83
|
+
if (e.key !== 'Enter' && e.key !== 'Escape') {
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
trigger.click();
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
69
88
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (
|
|
74
|
-
|
|
75
|
-
|
|
89
|
+
|
|
90
|
+
e.preventDefault();
|
|
91
|
+
|
|
92
|
+
if (e.key === 'Escape') {
|
|
93
|
+
closePopover();
|
|
94
|
+
return;
|
|
76
95
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
selectOption(option, dispatch = true) {
|
|
83
|
-
if (this.options.length === 0 || !option || option.disabled || option.getAttribute('data-value') == null) {
|
|
96
|
+
|
|
97
|
+
if (e.key === 'Enter') {
|
|
98
|
+
if (activeIndex > -1) {
|
|
99
|
+
selectOption(visibleOptions[activeIndex]);
|
|
100
|
+
}
|
|
84
101
|
return;
|
|
85
102
|
}
|
|
86
103
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
104
|
+
if (visibleOptions.length === 0) return;
|
|
105
|
+
|
|
106
|
+
const currentVisibleIndex = activeIndex > -1 ? visibleOptions.indexOf(options[activeIndex]) : -1;
|
|
107
|
+
let nextVisibleIndex = currentVisibleIndex;
|
|
108
|
+
|
|
109
|
+
switch (e.key) {
|
|
110
|
+
case 'ArrowDown':
|
|
111
|
+
if (currentVisibleIndex < visibleOptions.length - 1) {
|
|
112
|
+
nextVisibleIndex = currentVisibleIndex + 1;
|
|
113
|
+
}
|
|
114
|
+
break;
|
|
115
|
+
case 'ArrowUp':
|
|
116
|
+
if (currentVisibleIndex > 0) {
|
|
117
|
+
nextVisibleIndex = currentVisibleIndex - 1;
|
|
118
|
+
} else if (currentVisibleIndex === -1) {
|
|
119
|
+
nextVisibleIndex = 0; // Start from top if nothing is active
|
|
120
|
+
}
|
|
121
|
+
break;
|
|
122
|
+
case 'Home':
|
|
123
|
+
nextVisibleIndex = 0;
|
|
124
|
+
break;
|
|
125
|
+
case 'End':
|
|
126
|
+
nextVisibleIndex = visibleOptions.length - 1;
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (nextVisibleIndex !== currentVisibleIndex) {
|
|
131
|
+
if (currentVisibleIndex > -1) {
|
|
132
|
+
visibleOptions[currentVisibleIndex].classList.remove('active');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const newActiveOption = visibleOptions[nextVisibleIndex];
|
|
136
|
+
newActiveOption.classList.add('active');
|
|
137
|
+
activeIndex = options.indexOf(newActiveOption);
|
|
138
|
+
|
|
139
|
+
if (newActiveOption.id) {
|
|
140
|
+
trigger.setAttribute('aria-activedescendant', newActiveOption.id);
|
|
141
|
+
}
|
|
142
|
+
newActiveOption.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
|
|
98
143
|
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
trigger.addEventListener('keydown', handleKeyNavigation);
|
|
147
|
+
if (filter) {
|
|
148
|
+
filter.addEventListener('keydown', handleKeyNavigation);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
trigger.addEventListener('click', () => {
|
|
152
|
+
const isExpanded = trigger.getAttribute('aria-expanded') === 'true';
|
|
153
|
+
|
|
154
|
+
if (isExpanded) {
|
|
155
|
+
closePopover();
|
|
103
156
|
} else {
|
|
104
|
-
|
|
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
|
+
}
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
listbox.addEventListener('click', (e) => {
|
|
177
|
+
const clickedOption = e.target.closest('[role="option"]');
|
|
178
|
+
if (clickedOption) {
|
|
179
|
+
selectOption(clickedOption);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
document.addEventListener('click', (e) => {
|
|
184
|
+
if (!selectComponent.contains(e.target)) {
|
|
185
|
+
closePopover();
|
|
105
186
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
popover.setAttribute('aria-hidden', 'true');
|
|
190
|
+
selectComponent.dataset.selectInitialized = true;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
document.querySelectorAll('div.select:not([data-select-initialized])').forEach(initSelect);
|
|
194
|
+
|
|
195
|
+
const observer = new MutationObserver((mutations) => {
|
|
196
|
+
mutations.forEach((mutation) => {
|
|
197
|
+
mutation.addedNodes.forEach((node) => {
|
|
198
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
199
|
+
if (node.matches('div.select:not([data-select-initialized])')) {
|
|
200
|
+
initSelect(node);
|
|
201
|
+
}
|
|
202
|
+
node.querySelectorAll('div.select:not([data-select-initialized])').forEach(initSelect);
|
|
110
203
|
}
|
|
111
204
|
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
this.open = false;
|
|
118
|
-
this.$refs.trigger.focus();
|
|
119
|
-
},
|
|
120
|
-
'@keydown.down.prevent'() { this.moveOptionFocus(+1); },
|
|
121
|
-
'@keydown.up.prevent'() { this.moveOptionFocus(-1); },
|
|
122
|
-
'@keydown.home.prevent'() { this.focusOption(0) },
|
|
123
|
-
'@keydown.end.prevent'() { this.focusOption(this.options.length - 1) },
|
|
124
|
-
'@keydown.enter.prevent'() {
|
|
125
|
-
if (this.open) this.handleOptionEnter();
|
|
126
|
-
else this.open = true;
|
|
127
|
-
},
|
|
128
|
-
':aria-expanded'() { return this.open },
|
|
129
|
-
'x-ref': 'trigger'
|
|
130
|
-
},
|
|
131
|
-
$content: {
|
|
132
|
-
'@click'(e) { this.handleOptionClick(e) },
|
|
133
|
-
'@mouseover'(e) { this.handleOptionMousemove(e) },
|
|
134
|
-
':aria-hidden'() { return !this.open },
|
|
135
|
-
'x-cloak': ''
|
|
136
|
-
},
|
|
137
|
-
$filter: {
|
|
138
|
-
'@input'(e) { this.filterOptions(e.target.value) },
|
|
139
|
-
'@keydown.escape.prevent'() {
|
|
140
|
-
this.open = false;
|
|
141
|
-
this.$refs.trigger.focus();
|
|
142
|
-
},
|
|
143
|
-
'@keydown.down.prevent'() { this.moveOptionFocus(+1); },
|
|
144
|
-
'@keydown.up.prevent'() { this.moveOptionFocus(-1); },
|
|
145
|
-
'@keydown.home.prevent'() { this.focusOption(0) },
|
|
146
|
-
'@keydown.end.prevent'() { this.focusOption(this.options.length - 1) },
|
|
147
|
-
'@keydown.enter.prevent'() { this.handleOptionEnter() },
|
|
148
|
-
}
|
|
149
|
-
}));
|
|
150
|
-
};
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
209
|
+
})();
|
|
@@ -0,0 +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,25 +1,110 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
(() => {
|
|
2
|
+
// Monkey patching the history API to detect client-side navigation
|
|
3
|
+
if (!window.history.__basecoatPatched) {
|
|
4
|
+
const originalPushState = window.history.pushState;
|
|
5
|
+
window.history.pushState = function(...args) {
|
|
6
|
+
originalPushState.apply(this, args);
|
|
7
|
+
window.dispatchEvent(new Event('basecoat:locationchange'));
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const originalReplaceState = window.history.replaceState;
|
|
11
|
+
window.history.replaceState = function(...args) {
|
|
12
|
+
originalReplaceState.apply(this, args);
|
|
13
|
+
window.dispatchEvent(new Event('basecoat:locationchange'));
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
window.history.__basecoatPatched = true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const initSidebar = (sidebarComponent) => {
|
|
20
|
+
const initialOpen = sidebarComponent.dataset.initialOpen !== 'false';
|
|
21
|
+
const initialMobileOpen = sidebarComponent.dataset.initialMobileOpen === 'true';
|
|
22
|
+
const breakpoint = parseInt(sidebarComponent.dataset.breakpoint) || 768;
|
|
23
|
+
|
|
24
|
+
let open = breakpoint > 0
|
|
25
|
+
? (window.innerWidth >= breakpoint ? initialOpen : initialMobileOpen)
|
|
26
|
+
: initialOpen;
|
|
27
|
+
|
|
28
|
+
const updateCurrentPageLinks = () => {
|
|
29
|
+
const currentPath = window.location.pathname.replace(/\/$/, '');
|
|
30
|
+
sidebarComponent.querySelectorAll('a').forEach(link => {
|
|
31
|
+
if (link.hasAttribute('data-ignore-current')) return;
|
|
32
|
+
|
|
33
|
+
const linkPath = new URL(link.href).pathname.replace(/\/$/, '');
|
|
34
|
+
if (linkPath === currentPath) {
|
|
35
|
+
link.setAttribute('aria-current', 'page');
|
|
36
|
+
} else {
|
|
37
|
+
link.removeAttribute('aria-current');
|
|
38
|
+
}
|
|
13
39
|
});
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const updateState = () => {
|
|
43
|
+
sidebarComponent.setAttribute('aria-hidden', !open);
|
|
44
|
+
if (open) {
|
|
45
|
+
sidebarComponent.removeAttribute('inert');
|
|
46
|
+
} else {
|
|
47
|
+
sidebarComponent.setAttribute('inert', '');
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const setState = (state) => {
|
|
52
|
+
open = state;
|
|
53
|
+
updateState();
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const sidebarId = sidebarComponent.id;
|
|
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);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
sidebarComponent.addEventListener('click', (e) => {
|
|
69
|
+
const target = e.target;
|
|
70
|
+
const nav = sidebarComponent.querySelector('nav');
|
|
71
|
+
|
|
72
|
+
const isMobile = window.innerWidth < breakpoint;
|
|
73
|
+
|
|
74
|
+
if (isMobile && (target.closest('a, button') && !target.closest('[data-keep-mobile-sidebar-open]'))) {
|
|
75
|
+
if (document.activeElement) document.activeElement.blur();
|
|
76
|
+
setState(false);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (target === sidebarComponent || (nav && !nav.contains(target))) {
|
|
81
|
+
if (document.activeElement) document.activeElement.blur();
|
|
82
|
+
setState(false);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
window.addEventListener('popstate', updateCurrentPageLinks);
|
|
87
|
+
window.addEventListener('basecoat:locationchange', updateCurrentPageLinks);
|
|
88
|
+
|
|
89
|
+
updateState();
|
|
90
|
+
updateCurrentPageLinks();
|
|
91
|
+
sidebarComponent.dataset.sidebarInitialized = true;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
document.querySelectorAll('.sidebar:not([data-sidebar-initialized])').forEach(initSidebar);
|
|
95
|
+
|
|
96
|
+
const observer = new MutationObserver((mutations) => {
|
|
97
|
+
mutations.forEach((mutation) => {
|
|
98
|
+
mutation.addedNodes.forEach((node) => {
|
|
99
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
100
|
+
if (node.matches('.sidebar:not([data-sidebar-initialized])')) {
|
|
101
|
+
initSidebar(node);
|
|
102
|
+
}
|
|
103
|
+
node.querySelectorAll('.sidebar:not([data-sidebar-initialized])').forEach(initSidebar);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
110
|
+
})();
|
|
@@ -0,0 +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})})();
|
package/dist/assets/js/tabs.js
CHANGED
|
@@ -1,64 +1,75 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Alpine.data('tabs', (initialTabIndex = 0) => ({
|
|
6
|
-
activeTabIndex: initialTabIndex,
|
|
7
|
-
tabs: [],
|
|
8
|
-
panels: [],
|
|
1
|
+
(() => {
|
|
2
|
+
const initTabs = (tabsComponent) => {
|
|
3
|
+
const tablist = tabsComponent.querySelector('[role="tablist"]');
|
|
4
|
+
if (!tablist) return;
|
|
9
5
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
this.tabs = Array.from(this.$el.querySelectorAll(':scope > [role=tablist] [role=tab]:not([disabled])'));
|
|
13
|
-
this.panels = Array.from(this.$el.querySelectorAll(':scope > [role=tabpanel]'));
|
|
14
|
-
if (this.tabs.length > 0) {
|
|
15
|
-
this.selectTab(this.tabs[initialTabIndex], false);
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
},
|
|
19
|
-
nextTab() {
|
|
20
|
-
if (this.tabs.length === 0) return;
|
|
21
|
-
let newIndex = (this.activeTabIndex + 1) % this.tabs.length;
|
|
22
|
-
this.selectTab(this.tabs[newIndex]);
|
|
23
|
-
},
|
|
24
|
-
prevTab() {
|
|
25
|
-
if (this.tabs.length === 0) return;
|
|
26
|
-
let newIndex = (this.activeTabIndex - 1 + this.tabs.length) % this.tabs.length;
|
|
27
|
-
this.selectTab(this.tabs[newIndex]);
|
|
28
|
-
},
|
|
29
|
-
selectTab(tab, focus = true) {
|
|
30
|
-
if (!tab || this.tabs.length === 0) return;
|
|
6
|
+
const tabs = Array.from(tablist.querySelectorAll('[role="tab"]'));
|
|
7
|
+
const panels = tabs.map(tab => document.getElementById(tab.getAttribute('aria-controls'))).filter(Boolean);
|
|
31
8
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
-
this.activeTabIndex = index;
|
|
38
|
-
this.activeTab = t;
|
|
39
|
-
if (focus) {
|
|
40
|
-
t.focus();
|
|
41
|
-
}
|
|
42
|
-
}
|
|
9
|
+
const selectTab = (tabToSelect) => {
|
|
10
|
+
tabs.forEach((tab, index) => {
|
|
11
|
+
tab.setAttribute('aria-selected', 'false');
|
|
12
|
+
tab.setAttribute('tabindex', '-1');
|
|
13
|
+
if (panels[index]) panels[index].hidden = true;
|
|
43
14
|
});
|
|
44
15
|
|
|
45
|
-
|
|
46
|
-
|
|
16
|
+
tabToSelect.setAttribute('aria-selected', 'true');
|
|
17
|
+
tabToSelect.setAttribute('tabindex', '0');
|
|
18
|
+
const activePanel = document.getElementById(tabToSelect.getAttribute('aria-controls'));
|
|
19
|
+
if (activePanel) activePanel.hidden = false;
|
|
20
|
+
};
|
|
47
21
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
22
|
+
tablist.addEventListener('click', (e) => {
|
|
23
|
+
const clickedTab = e.target.closest('[role="tab"]');
|
|
24
|
+
if (clickedTab) selectTab(clickedTab);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
tablist.addEventListener('keydown', (e) => {
|
|
28
|
+
const currentTab = e.target;
|
|
29
|
+
if (!tabs.includes(currentTab)) return;
|
|
30
|
+
|
|
31
|
+
let nextTab;
|
|
32
|
+
const currentIndex = tabs.indexOf(currentTab);
|
|
52
33
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
34
|
+
switch (e.key) {
|
|
35
|
+
case 'ArrowRight':
|
|
36
|
+
nextTab = tabs[(currentIndex + 1) % tabs.length];
|
|
37
|
+
break;
|
|
38
|
+
case 'ArrowLeft':
|
|
39
|
+
nextTab = tabs[(currentIndex - 1 + tabs.length) % tabs.length];
|
|
40
|
+
break;
|
|
41
|
+
case 'Home':
|
|
42
|
+
nextTab = tabs[0];
|
|
43
|
+
break;
|
|
44
|
+
case 'End':
|
|
45
|
+
nextTab = tabs[tabs.length - 1];
|
|
46
|
+
break;
|
|
47
|
+
default:
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
e.preventDefault();
|
|
52
|
+
selectTab(nextTab);
|
|
53
|
+
nextTab.focus();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
tabsComponent.dataset.tabsInitialized = true;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
document.querySelectorAll('.tabs:not([data-tabs-initialized])').forEach(initTabs);
|
|
60
|
+
|
|
61
|
+
const observer = new MutationObserver((mutations) => {
|
|
62
|
+
mutations.forEach((mutation) => {
|
|
63
|
+
mutation.addedNodes.forEach((node) => {
|
|
64
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
65
|
+
if (node.matches('.tabs:not([data-tabs-initialized])')) {
|
|
66
|
+
initTabs(node);
|
|
58
67
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
|
-
|
|
68
|
+
node.querySelectorAll('.tabs:not([data-tabs-initialized])').forEach(initTabs);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
75
|
+
})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(()=>{const e=e=>{const t=e.querySelector('[role="tablist"]');if(!t)return;const a=Array.from(t.querySelectorAll('[role="tab"]')),r=a.map((e=>document.getElementById(e.getAttribute("aria-controls")))).filter(Boolean),n=e=>{a.forEach(((e,t)=>{e.setAttribute("aria-selected","false"),e.setAttribute("tabindex","-1"),r[t]&&(r[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&&n(t)})),t.addEventListener("keydown",(e=>{const t=e.target;if(!a.includes(t))return;let r;const o=a.indexOf(t);switch(e.key){case"ArrowRight":r=a[(o+1)%a.length];break;case"ArrowLeft":r=a[(o-1+a.length)%a.length];break;case"Home":r=a[0];break;case"End":r=a[a.length-1];break;default:return}e.preventDefault(),n(r),r.focus()})),e.dataset.tabsInitialized=!0};document.querySelectorAll(".tabs:not([data-tabs-initialized])").forEach(e);new MutationObserver((t=>{t.forEach((t=>{t.addedNodes.forEach((t=>{t.nodeType===Node.ELEMENT_NODE&&(t.matches(".tabs:not([data-tabs-initialized])")&&e(t),t.querySelectorAll(".tabs:not([data-tabs-initialized])").forEach(e))}))}))})).observe(document.body,{childList:!0,subtree:!0})})();
|