@auvyx/ui 0.0.0-stage → 0.1.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/LICENSE +48 -0
- package/README.md +43 -2
- package/dist/auvyx.bundle.css +5941 -0
- package/dist/auvyx.chart.min.js +2 -0
- package/dist/auvyx.corners.min.js +2 -0
- package/dist/auvyx.css +10880 -0
- package/dist/auvyx.js +3222 -0
- package/dist/auvyx.min.css +2 -0
- package/dist/auvyx.min.js +19 -0
- package/dist/custom-elements.json +948 -0
- package/dist/elements/calendar.min.js +2 -0
- package/dist/elements/context-menu.min.js +2 -0
- package/dist/elements/data-table.min.js +2 -0
- package/dist/elements/date-picker.min.js +2 -0
- package/dist/elements/index.min.js +2 -0
- package/dist/elements/menu.min.js +2 -0
- package/dist/elements/resizable.min.js +2 -0
- package/dist/js/accordion.min.js +2 -0
- package/dist/js/calendar.min.js +2 -0
- package/dist/js/combobox.min.js +2 -0
- package/dist/js/command.min.js +2 -0
- package/dist/js/context-menu.min.js +2 -0
- package/dist/js/copy.min.js +2 -0
- package/dist/js/data-table.min.js +2 -0
- package/dist/js/date-picker.min.js +2 -0
- package/dist/js/drawer.min.js +2 -0
- package/dist/js/dropdown-menu.min.js +2 -0
- package/dist/js/manifest.json +114 -0
- package/dist/js/menu.min.js +2 -0
- package/dist/js/popover.min.js +2 -0
- package/dist/js/resizable.min.js +2 -0
- package/dist/js/select.min.js +2 -0
- package/dist/js/sidebar.min.js +2 -0
- package/dist/js/slider.min.js +2 -0
- package/dist/js/tabs.min.js +2 -0
- package/dist/js/toast.min.js +19 -0
- package/dist/styles/auvyx-luma.min.css +3 -0
- package/dist/styles/auvyx-lyra.min.css +3 -0
- package/dist/styles/auvyx-maia.min.css +3 -0
- package/dist/styles/auvyx-mira.min.css +3 -0
- package/dist/styles/auvyx-nova.min.css +3 -0
- package/dist/styles/auvyx-rhea.min.css +3 -0
- package/dist/styles/auvyx-sera.min.css +3 -0
- package/dist/styles/auvyx-vega.min.css +3 -0
- package/dist/types/elements.d.ts +262 -0
- package/dist/types/react.d.ts +181 -0
- package/dist/types/vue.d.ts +155 -0
- package/dist/ui/accordion.css +91 -0
- package/dist/ui/accordion.js +249 -0
- package/dist/ui/accordion.native.css +24 -0
- package/dist/ui/alert.css +119 -0
- package/dist/ui/aspect-ratio.css +38 -0
- package/dist/ui/attachment.css +211 -0
- package/dist/ui/avatar.css +204 -0
- package/dist/ui/badge.css +183 -0
- package/dist/ui/base.css +1200 -0
- package/dist/ui/breadcrumb.css +90 -0
- package/dist/ui/bubble.css +171 -0
- package/dist/ui/button-group.css +110 -0
- package/dist/ui/button.css +328 -0
- package/dist/ui/calendar.css +260 -0
- package/dist/ui/calendar.js +317 -0
- package/dist/ui/card.css +126 -0
- package/dist/ui/carousel.css +172 -0
- package/dist/ui/chart.css +130 -0
- package/dist/ui/checkbox.css +119 -0
- package/dist/ui/code-block.css +235 -0
- package/dist/ui/combobox.css +500 -0
- package/dist/ui/combobox.js +757 -0
- package/dist/ui/command.css +366 -0
- package/dist/ui/command.js +382 -0
- package/dist/ui/context-menu.css +17 -0
- package/dist/ui/context-menu.js +52 -0
- package/dist/ui/copy.js +56 -0
- package/dist/ui/data-table.css +114 -0
- package/dist/ui/data-table.js +140 -0
- package/dist/ui/date-picker.css +14 -0
- package/dist/ui/date-picker.js +101 -0
- package/dist/ui/dialog.css +363 -0
- package/dist/ui/dialog.native.css +6 -0
- package/dist/ui/drawer.css +238 -0
- package/dist/ui/drawer.js +265 -0
- package/dist/ui/dropdown-menu.css +193 -0
- package/dist/ui/dropdown-menu.js +388 -0
- package/dist/ui/empty.css +111 -0
- package/dist/ui/field.css +293 -0
- package/dist/ui/hover-card.css +85 -0
- package/dist/ui/input-group.css +269 -0
- package/dist/ui/input-otp.css +101 -0
- package/dist/ui/input.css +117 -0
- package/dist/ui/item.css +223 -0
- package/dist/ui/kbd.css +50 -0
- package/dist/ui/label.css +48 -0
- package/dist/ui/manifest.json +667 -0
- package/dist/ui/marker.css +66 -0
- package/dist/ui/menu.js +161 -0
- package/dist/ui/menubar.css +55 -0
- package/dist/ui/message-scroller.css +83 -0
- package/dist/ui/message.css +69 -0
- package/dist/ui/native-select.css +130 -0
- package/dist/ui/navigation-menu.css +166 -0
- package/dist/ui/popover.css +154 -0
- package/dist/ui/popover.js +268 -0
- package/dist/ui/popover.native.css +84 -0
- package/dist/ui/progress.css +29 -0
- package/dist/ui/questionnaire.css +188 -0
- package/dist/ui/radio-group.css +115 -0
- package/dist/ui/resizable.css +94 -0
- package/dist/ui/resizable.js +95 -0
- package/dist/ui/scroll-area.css +43 -0
- package/dist/ui/select.css +289 -0
- package/dist/ui/select.js +646 -0
- package/dist/ui/sheet.css +219 -0
- package/dist/ui/sidebar.css +716 -0
- package/dist/ui/sidebar.js +287 -0
- package/dist/ui/skeleton.css +13 -0
- package/dist/ui/slider.css +184 -0
- package/dist/ui/slider.js +206 -0
- package/dist/ui/switch.css +156 -0
- package/dist/ui/table.css +157 -0
- package/dist/ui/tabs.css +240 -0
- package/dist/ui/tabs.js +288 -0
- package/dist/ui/textarea.css +91 -0
- package/dist/ui/toast.css +110 -0
- package/dist/ui/toast.js +378 -0
- package/dist/ui/toggle-group.css +42 -0
- package/dist/ui/toggle.css +150 -0
- package/dist/ui/tooltip.css +319 -0
- package/dist/ui/trace.css +142 -0
- package/dist/ui/typography.css +184 -0
- package/dist/wc/accordion.min.js +2 -0
- package/dist/wc/combobox.min.js +2 -0
- package/dist/wc/command.min.js +2 -0
- package/dist/wc/drawer.min.js +2 -0
- package/dist/wc/dropdown-menu.min.js +2 -0
- package/dist/wc/manifest.json +154 -0
- package/dist/wc/popover.min.js +2 -0
- package/dist/wc/select.min.js +2 -0
- package/dist/wc/sidebar.min.js +2 -0
- package/dist/wc/slider.min.js +2 -0
- package/dist/wc/tabs.min.js +2 -0
- package/dist/wc/toast.min.js +19 -0
- package/package.json +62 -4
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
/* @auvyx/ui v0.1.0 | MIT | based on Basecoat (MIT) */
|
|
2
|
+
// Basecoat core, once per page.
|
|
3
|
+
if (!window.basecoat) (() => {
|
|
4
|
+
const componentRegistry = {};
|
|
5
|
+
let observer = null;
|
|
6
|
+
|
|
7
|
+
const registerComponent = (name, selectorOrOptions, initFunction) => {
|
|
8
|
+
const options = typeof selectorOrOptions === 'object'
|
|
9
|
+
? selectorOrOptions
|
|
10
|
+
: { selector: selectorOrOptions, init: initFunction };
|
|
11
|
+
|
|
12
|
+
componentRegistry[name] = {
|
|
13
|
+
selector: options.selector,
|
|
14
|
+
init: options.init,
|
|
15
|
+
refresh: options.refresh,
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const initComponent = (element, componentName) => {
|
|
20
|
+
const component = componentRegistry[componentName];
|
|
21
|
+
if (!component) return;
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
component.init(element);
|
|
25
|
+
if (element.hasAttribute(`data-${componentName}-initialized`)) {
|
|
26
|
+
element.dataset.basecoatComponent = componentName;
|
|
27
|
+
}
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error(`Failed to initialize ${componentName}:`, error);
|
|
30
|
+
if (typeof element._destroy === 'function') {
|
|
31
|
+
try {
|
|
32
|
+
element._destroy();
|
|
33
|
+
} catch (destroyError) {
|
|
34
|
+
console.error(`Failed to clean up ${componentName} after initialization error:`, destroyError);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
delete element._destroy;
|
|
38
|
+
element.removeAttribute(`data-${componentName}-initialized`);
|
|
39
|
+
delete element.dataset.basecoatComponent;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const destroyComponent = (element) => {
|
|
44
|
+
if (!element || element.nodeType !== Node.ELEMENT_NODE) return;
|
|
45
|
+
const componentName = element.dataset?.basecoatComponent;
|
|
46
|
+
|
|
47
|
+
if (typeof element._destroy === 'function') {
|
|
48
|
+
try {
|
|
49
|
+
element._destroy();
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.error('Failed to destroy Basecoat component:', error);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
delete element._destroy;
|
|
56
|
+
if (componentName) element.removeAttribute(`data-${componentName}-initialized`);
|
|
57
|
+
delete element.dataset.basecoatComponent;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const destroyRemovedComponents = (node) => {
|
|
61
|
+
if (node.nodeType !== Node.ELEMENT_NODE) return;
|
|
62
|
+
if (node.isConnected) return;
|
|
63
|
+
|
|
64
|
+
if (node.dataset?.basecoatComponent) destroyComponent(node);
|
|
65
|
+
node.querySelectorAll('[data-basecoat-component]').forEach(destroyComponent);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const uniqueElements = (elements) => Array.from(new Set(elements));
|
|
69
|
+
|
|
70
|
+
const getComponentElements = (componentName, selector, force = false) => {
|
|
71
|
+
const elements = Array.from(document.querySelectorAll(selector));
|
|
72
|
+
if (force) {
|
|
73
|
+
elements.push(...document.querySelectorAll(`[data-basecoat-component="${componentName}"]`));
|
|
74
|
+
}
|
|
75
|
+
return uniqueElements(elements);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const initAllComponents = (options = {}) => {
|
|
79
|
+
const force = options.force === true;
|
|
80
|
+
Object.entries(componentRegistry).forEach(([name, { selector }]) => {
|
|
81
|
+
getComponentElements(name, selector, force).forEach((element) => {
|
|
82
|
+
const wasComponent = element.dataset?.basecoatComponent === name;
|
|
83
|
+
if (force) destroyComponent(element);
|
|
84
|
+
if (wasComponent || element.matches(selector)) initComponent(element, name);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const initNewComponents = (node) => {
|
|
90
|
+
if (node.nodeType !== Node.ELEMENT_NODE) return;
|
|
91
|
+
|
|
92
|
+
Object.entries(componentRegistry).forEach(([name, { selector }]) => {
|
|
93
|
+
if (node.matches(selector)) initComponent(node, name);
|
|
94
|
+
node.querySelectorAll(selector).forEach(element => initComponent(element, name));
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const refreshComponent = (element) => {
|
|
99
|
+
if (!element) return;
|
|
100
|
+
if (typeof element.refresh === 'function') {
|
|
101
|
+
element.refresh();
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const componentName = element.dataset?.basecoatComponent;
|
|
106
|
+
const component = componentName ? componentRegistry[componentName] : null;
|
|
107
|
+
if (component?.refresh) {
|
|
108
|
+
component.refresh(element);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const startObserver = () => {
|
|
113
|
+
if (observer) return;
|
|
114
|
+
|
|
115
|
+
observer = new MutationObserver((mutations) => {
|
|
116
|
+
mutations.forEach((mutation) => {
|
|
117
|
+
mutation.addedNodes.forEach(initNewComponents);
|
|
118
|
+
mutation.removedNodes.forEach(destroyRemovedComponents);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const stopObserver = () => {
|
|
126
|
+
if (!observer) return;
|
|
127
|
+
observer.disconnect();
|
|
128
|
+
observer = null;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const initRegisteredComponent = (componentName, options = {}) => {
|
|
132
|
+
const component = componentRegistry[componentName];
|
|
133
|
+
if (!component) {
|
|
134
|
+
console.warn(`Component '${componentName}' not found in registry`);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const force = options.force === true;
|
|
139
|
+
getComponentElements(componentName, component.selector, force).forEach((element) => {
|
|
140
|
+
const wasComponent = element.dataset?.basecoatComponent === componentName;
|
|
141
|
+
if (force) destroyComponent(element);
|
|
142
|
+
if (wasComponent || element.matches(component.selector)) initComponent(element, componentName);
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const initAllRegisteredComponents = (options = {}) => {
|
|
147
|
+
initAllComponents(options);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const setTheme = (mode) => {
|
|
151
|
+
const dark = mode === 'dark';
|
|
152
|
+
document.documentElement.classList.toggle('dark', dark);
|
|
153
|
+
try { localStorage.setItem('themeMode', dark ? 'dark' : 'light'); } catch (_) {}
|
|
154
|
+
document.dispatchEvent(new CustomEvent('basecoat:themechange', { detail: { mode: dark ? 'dark' : 'light' } }));
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const getTheme = () => document.documentElement.classList.contains('dark') ? 'dark' : 'light';
|
|
158
|
+
|
|
159
|
+
window.basecoat = {
|
|
160
|
+
register: registerComponent,
|
|
161
|
+
init: initRegisteredComponent,
|
|
162
|
+
initAll: initAllRegisteredComponents,
|
|
163
|
+
refresh: refreshComponent,
|
|
164
|
+
start: startObserver,
|
|
165
|
+
stop: stopObserver,
|
|
166
|
+
theme: {
|
|
167
|
+
get: getTheme,
|
|
168
|
+
set: setTheme,
|
|
169
|
+
toggle: () => setTheme(getTheme() === 'dark' ? 'light' : 'dark'),
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
174
|
+
initAllComponents();
|
|
175
|
+
startObserver();
|
|
176
|
+
});
|
|
177
|
+
})();
|
|
178
|
+
|
|
179
|
+
(() => {
|
|
180
|
+
const states = new WeakMap();
|
|
181
|
+
|
|
182
|
+
const isDisabled = (item) =>
|
|
183
|
+
item.hasAttribute('disabled') ||
|
|
184
|
+
item.getAttribute('aria-disabled') === 'true' ||
|
|
185
|
+
item.getAttribute('data-disabled') === 'true';
|
|
186
|
+
|
|
187
|
+
const getElements = (container) => ({
|
|
188
|
+
input: container.querySelector('header input'),
|
|
189
|
+
menu: container.querySelector('[role="menu"]'),
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const getItems = (menu) => {
|
|
193
|
+
const allItems = Array.from(menu.querySelectorAll('[role="menuitem"]'));
|
|
194
|
+
return {
|
|
195
|
+
allItems,
|
|
196
|
+
items: allItems.filter(item => !isDisabled(item)),
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
const scrollItemIntoMenu = (state, item) => {
|
|
201
|
+
const itemRect = item.getBoundingClientRect();
|
|
202
|
+
const menuRect = state.menu.getBoundingClientRect();
|
|
203
|
+
|
|
204
|
+
if (itemRect.top < menuRect.top) {
|
|
205
|
+
state.menu.scrollTop -= menuRect.top - itemRect.top;
|
|
206
|
+
} else if (itemRect.bottom > menuRect.bottom) {
|
|
207
|
+
state.menu.scrollTop += itemRect.bottom - menuRect.bottom;
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const setActiveItem = (state, index) => {
|
|
212
|
+
if (state.activeIndex > -1 && state.items[state.activeIndex]) {
|
|
213
|
+
state.items[state.activeIndex].classList.remove('active');
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
state.activeIndex = index;
|
|
217
|
+
|
|
218
|
+
if (state.activeIndex > -1) {
|
|
219
|
+
const activeItem = state.items[state.activeIndex];
|
|
220
|
+
activeItem.classList.add('active');
|
|
221
|
+
if (activeItem.id) {
|
|
222
|
+
state.input.setAttribute('aria-activedescendant', activeItem.id);
|
|
223
|
+
} else {
|
|
224
|
+
state.input.removeAttribute('aria-activedescendant');
|
|
225
|
+
}
|
|
226
|
+
} else {
|
|
227
|
+
state.input.removeAttribute('aria-activedescendant');
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
const filterItems = (state) => {
|
|
232
|
+
if (state.manualFilter) {
|
|
233
|
+
setActiveItem(state, -1);
|
|
234
|
+
state.visibleItems = state.items.filter(item => item.getAttribute('aria-hidden') !== 'true');
|
|
235
|
+
if (state.visibleItems.length > 0) {
|
|
236
|
+
setActiveItem(state, state.items.indexOf(state.visibleItems[0]));
|
|
237
|
+
}
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const searchTerm = state.input.value.trim().toLowerCase();
|
|
242
|
+
|
|
243
|
+
setActiveItem(state, -1);
|
|
244
|
+
state.visibleItems = [];
|
|
245
|
+
|
|
246
|
+
state.allItems.forEach(item => {
|
|
247
|
+
if (item.hasAttribute('data-force')) {
|
|
248
|
+
item.setAttribute('aria-hidden', 'false');
|
|
249
|
+
if (state.items.includes(item)) state.visibleItems.push(item);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const itemText = (item.dataset.filter || item.textContent).trim().toLowerCase();
|
|
254
|
+
const keywordList = (item.dataset.keywords || '')
|
|
255
|
+
.toLowerCase()
|
|
256
|
+
.split(/[\s,]+/)
|
|
257
|
+
.filter(Boolean);
|
|
258
|
+
const matchesKeyword = keywordList.some(keyword => keyword.includes(searchTerm));
|
|
259
|
+
const matches = itemText.includes(searchTerm) || matchesKeyword;
|
|
260
|
+
item.setAttribute('aria-hidden', String(!matches));
|
|
261
|
+
if (matches && state.items.includes(item)) state.visibleItems.push(item);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
if (state.visibleItems.length > 0) {
|
|
265
|
+
setActiveItem(state, state.items.indexOf(state.visibleItems[0]));
|
|
266
|
+
scrollItemIntoMenu(state, state.visibleItems[0]);
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
const refreshCommand = (container) => {
|
|
271
|
+
const state = states.get(container);
|
|
272
|
+
if (!state) return;
|
|
273
|
+
|
|
274
|
+
const elements = getElements(container);
|
|
275
|
+
if (!elements.input || !elements.menu) {
|
|
276
|
+
const missing = [];
|
|
277
|
+
if (!elements.input) missing.push('input');
|
|
278
|
+
if (!elements.menu) missing.push('menu');
|
|
279
|
+
console.error(`Command component refresh failed. Missing element(s): ${missing.join(', ')}`, container);
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
Object.assign(state, elements, getItems(elements.menu));
|
|
284
|
+
state.manualFilter = container.dataset.filter === 'manual';
|
|
285
|
+
filterItems(state);
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
const handleKeyNavigation = (event, state) => {
|
|
289
|
+
if (!['ArrowDown', 'ArrowUp', 'Enter', 'Home', 'End'].includes(event.key)) return;
|
|
290
|
+
|
|
291
|
+
if (event.key === 'Enter') {
|
|
292
|
+
event.preventDefault();
|
|
293
|
+
if (state.activeIndex > -1) state.items[state.activeIndex]?.click();
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (state.visibleItems.length === 0) return;
|
|
298
|
+
|
|
299
|
+
event.preventDefault();
|
|
300
|
+
|
|
301
|
+
const currentVisibleIndex = state.activeIndex > -1 ? state.visibleItems.indexOf(state.items[state.activeIndex]) : -1;
|
|
302
|
+
let nextVisibleIndex = currentVisibleIndex;
|
|
303
|
+
|
|
304
|
+
if (event.key === 'ArrowDown' && currentVisibleIndex < state.visibleItems.length - 1) nextVisibleIndex = currentVisibleIndex + 1;
|
|
305
|
+
if (event.key === 'ArrowUp') nextVisibleIndex = currentVisibleIndex > 0 ? currentVisibleIndex - 1 : 0;
|
|
306
|
+
if (event.key === 'Home') nextVisibleIndex = 0;
|
|
307
|
+
if (event.key === 'End') nextVisibleIndex = state.visibleItems.length - 1;
|
|
308
|
+
|
|
309
|
+
if (nextVisibleIndex !== currentVisibleIndex) {
|
|
310
|
+
const newActiveItem = state.visibleItems[nextVisibleIndex];
|
|
311
|
+
setActiveItem(state, state.items.indexOf(newActiveItem));
|
|
312
|
+
scrollItemIntoMenu(state, newActiveItem);
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
const initCommand = (container) => {
|
|
317
|
+
if (container.dataset.commandInitialized) return;
|
|
318
|
+
|
|
319
|
+
const state = { activeIndex: -1, allItems: [], items: [], visibleItems: [], manualFilter: false };
|
|
320
|
+
states.set(container, state);
|
|
321
|
+
|
|
322
|
+
container.refresh = () => refreshCommand(container);
|
|
323
|
+
|
|
324
|
+
const elements = getElements(container);
|
|
325
|
+
if (!elements.input || !elements.menu) {
|
|
326
|
+
const missing = [];
|
|
327
|
+
if (!elements.input) missing.push('input');
|
|
328
|
+
if (!elements.menu) missing.push('menu');
|
|
329
|
+
console.error(`Command component initialization failed. Missing element(s): ${missing.join(', ')}`, container);
|
|
330
|
+
states.delete(container);
|
|
331
|
+
delete container.refresh;
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
Object.assign(state, elements);
|
|
335
|
+
|
|
336
|
+
const handleInput = () => filterItems(state);
|
|
337
|
+
const handleInputKeydown = (event) => handleKeyNavigation(event, state);
|
|
338
|
+
const handleMenuMousemove = (event) => {
|
|
339
|
+
const menuItem = event.target.closest('[role="menuitem"]');
|
|
340
|
+
if (menuItem && state.visibleItems.includes(menuItem)) {
|
|
341
|
+
const index = state.items.indexOf(menuItem);
|
|
342
|
+
if (index !== state.activeIndex) setActiveItem(state, index);
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
const handleMenuClick = (event) => {
|
|
346
|
+
const clickedItem = event.target.closest('[role="menuitem"]');
|
|
347
|
+
if (clickedItem && state.visibleItems.includes(clickedItem)) {
|
|
348
|
+
const dialog = container.closest('dialog.command-dialog');
|
|
349
|
+
if (dialog && !clickedItem.hasAttribute('data-keep-command-open')) dialog.close();
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
state.input.addEventListener('input', handleInput);
|
|
354
|
+
state.input.addEventListener('keydown', handleInputKeydown);
|
|
355
|
+
state.menu.addEventListener('mousemove', handleMenuMousemove);
|
|
356
|
+
state.menu.addEventListener('click', handleMenuClick);
|
|
357
|
+
|
|
358
|
+
container._destroy = () => {
|
|
359
|
+
state.input.removeEventListener('input', handleInput);
|
|
360
|
+
state.input.removeEventListener('keydown', handleInputKeydown);
|
|
361
|
+
state.menu.removeEventListener('mousemove', handleMenuMousemove);
|
|
362
|
+
state.menu.removeEventListener('click', handleMenuClick);
|
|
363
|
+
states.delete(container);
|
|
364
|
+
delete container.refresh;
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
refreshCommand(container);
|
|
368
|
+
container.dataset.commandInitialized = 'true';
|
|
369
|
+
container.dispatchEvent(new CustomEvent('basecoat:initialized'));
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
if (window.basecoat) {
|
|
373
|
+
window.basecoat.register('command', {
|
|
374
|
+
selector: '.command:not([data-command-initialized])',
|
|
375
|
+
init: initCommand,
|
|
376
|
+
refresh: refreshCommand,
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
})();
|
|
380
|
+
|
|
381
|
+
// Loaded after the DOM is ready: initialize now.
|
|
382
|
+
if (document.readyState !== 'loading') { window.basecoat.initAll(); window.basecoat.start(); }
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* @auvyx/ui context-menu | order 54 */
|
|
2
|
+
@layer components {
|
|
3
|
+
.context-menu {
|
|
4
|
+
display: block;
|
|
5
|
+
> .dropdown-menu {
|
|
6
|
+
display: contents;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
@layer components {
|
|
12
|
+
.context-menu > .dropdown-menu > [data-popover] {
|
|
13
|
+
min-width: calc(var(--spacing) * 36);
|
|
14
|
+
--tw-shadow: var(--shadow-md, 0 4px 6px -1px var(--tw-shadow-color, rgb(0 0 0 / 0.1)), 0 2px 4px -2px var(--tw-shadow-color, rgb(0 0 0 / 0.1)));
|
|
15
|
+
box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/* @auvyx/ui v0.1.0 | MIT | based on Basecoat (MIT) */
|
|
2
|
+
(() => {
|
|
3
|
+
// ../elements/src/context-menu.js
|
|
4
|
+
var AuvyxContextMenu = class extends HTMLElement {
|
|
5
|
+
connectedCallback() {
|
|
6
|
+
if (this._init) return;
|
|
7
|
+
this._init = true;
|
|
8
|
+
this.menu = this.querySelector("[data-popover][popover]");
|
|
9
|
+
if (!this.menu) return;
|
|
10
|
+
let pressed = false;
|
|
11
|
+
this.addEventListener("pointerdown", (e) => {
|
|
12
|
+
if (e.button === 2) pressed = true;
|
|
13
|
+
});
|
|
14
|
+
this.addEventListener("contextmenu", (event) => {
|
|
15
|
+
if (this.menu.contains(event.target)) return;
|
|
16
|
+
event.preventDefault();
|
|
17
|
+
const { clientX: x, clientY: y } = event;
|
|
18
|
+
if (!pressed) return this.openAt(x, y);
|
|
19
|
+
window.addEventListener("pointerup", () => {
|
|
20
|
+
pressed = false;
|
|
21
|
+
setTimeout(() => this.openAt(x, y));
|
|
22
|
+
}, { once: true, capture: true });
|
|
23
|
+
});
|
|
24
|
+
this.addEventListener("keydown", (event) => {
|
|
25
|
+
if (this.menu.contains(event.target)) return;
|
|
26
|
+
if (event.key === "ContextMenu" || event.shiftKey && event.key === "F10") {
|
|
27
|
+
event.preventDefault();
|
|
28
|
+
const r = event.target.getBoundingClientRect();
|
|
29
|
+
this.openAt(r.left, r.bottom);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
openAt(x, y) {
|
|
34
|
+
const menu = this.menu;
|
|
35
|
+
if (menu.matches(":popover-open")) menu.hidePopover();
|
|
36
|
+
Object.assign(menu.style, {
|
|
37
|
+
position: "fixed",
|
|
38
|
+
inset: "auto",
|
|
39
|
+
margin: "0",
|
|
40
|
+
positionArea: "none",
|
|
41
|
+
positionTryFallbacks: "none",
|
|
42
|
+
left: `${x}px`,
|
|
43
|
+
top: `${y}px`
|
|
44
|
+
});
|
|
45
|
+
menu.showPopover();
|
|
46
|
+
const r = menu.getBoundingClientRect();
|
|
47
|
+
if (r.right > innerWidth - 4) menu.style.left = `${Math.max(4, x - r.width)}px`;
|
|
48
|
+
if (r.bottom > innerHeight - 4) menu.style.top = `${Math.max(4, y - r.height)}px`;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
if (!customElements.get("auvyx-context-menu")) customElements.define("auvyx-context-menu", AuvyxContextMenu);
|
|
52
|
+
})();
|
package/dist/ui/copy.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/* @auvyx/ui v0.1.0 | MIT | based on Basecoat (MIT) */
|
|
2
|
+
// Copy to clipboard (fork addition).
|
|
3
|
+
//
|
|
4
|
+
// Any element with [data-copy] copies text on click:
|
|
5
|
+
// data-copy="" → the <pre> of the closest .code-block
|
|
6
|
+
// data-copy="#selector" → the textContent of that element
|
|
7
|
+
// data-copy-text="…" → this literal text
|
|
8
|
+
// While copied, the button gets [data-copied] for 2s and its aria-label
|
|
9
|
+
// becomes the value of data-copied-label (default "Copied").
|
|
10
|
+
// One delegated listener, so it also works for content added later.
|
|
11
|
+
(() => {
|
|
12
|
+
if (window.__basecoatCopy) return;
|
|
13
|
+
window.__basecoatCopy = true;
|
|
14
|
+
|
|
15
|
+
const sourceText = (button) => {
|
|
16
|
+
if (button.hasAttribute('data-copy-text')) return button.getAttribute('data-copy-text');
|
|
17
|
+
const target = button.getAttribute('data-copy');
|
|
18
|
+
const el = target ? document.querySelector(target) : button.closest('.code-block')?.querySelector(':scope > pre');
|
|
19
|
+
return el ? el.textContent : null;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const selectFallback = (button) => {
|
|
23
|
+
const target = button.getAttribute('data-copy');
|
|
24
|
+
const el = target ? document.querySelector(target) : button.closest('.code-block')?.querySelector(':scope > pre');
|
|
25
|
+
if (!el) return;
|
|
26
|
+
const range = document.createRange();
|
|
27
|
+
range.selectNodeContents(el);
|
|
28
|
+
const selection = window.getSelection();
|
|
29
|
+
selection.removeAllRanges();
|
|
30
|
+
selection.addRange(range);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
document.addEventListener('click', async (event) => {
|
|
34
|
+
const button = event.target.closest('[data-copy], [data-copy-text]');
|
|
35
|
+
if (!button || button.disabled) return;
|
|
36
|
+
const text = sourceText(button);
|
|
37
|
+
if (text == null) return;
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
await navigator.clipboard.writeText(text.replace(/\n$/, ''));
|
|
41
|
+
} catch {
|
|
42
|
+
selectFallback(button);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const label = button.getAttribute('aria-label');
|
|
47
|
+
if (!button.hasAttribute('data-copied')) button.dataset.copyLabel = label ?? '';
|
|
48
|
+
button.setAttribute('data-copied', '');
|
|
49
|
+
button.setAttribute('aria-label', button.getAttribute('data-copied-label') || 'Copied');
|
|
50
|
+
clearTimeout(button._copyTimer);
|
|
51
|
+
button._copyTimer = setTimeout(() => {
|
|
52
|
+
button.removeAttribute('data-copied');
|
|
53
|
+
if (button.dataset.copyLabel) button.setAttribute('aria-label', button.dataset.copyLabel);
|
|
54
|
+
}, 2000);
|
|
55
|
+
});
|
|
56
|
+
})();
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/* @auvyx/ui data-table | order 56 */
|
|
2
|
+
@layer components {
|
|
3
|
+
.data-table {
|
|
4
|
+
display: flex;
|
|
5
|
+
width: 100%;
|
|
6
|
+
min-width: 0;
|
|
7
|
+
flex-direction: column;
|
|
8
|
+
> header, > footer {
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-wrap: wrap;
|
|
11
|
+
align-items: center;
|
|
12
|
+
}
|
|
13
|
+
> header > input {
|
|
14
|
+
width: auto;
|
|
15
|
+
min-width: 0;
|
|
16
|
+
flex: 1 1 12rem;
|
|
17
|
+
}
|
|
18
|
+
> div:has(> table) {
|
|
19
|
+
position: relative;
|
|
20
|
+
width: 100%;
|
|
21
|
+
overflow-x: auto;
|
|
22
|
+
}
|
|
23
|
+
th[aria-sort] > button {
|
|
24
|
+
display: inline-flex;
|
|
25
|
+
align-items: center;
|
|
26
|
+
white-space: nowrap;
|
|
27
|
+
--tw-outline-style: none;
|
|
28
|
+
outline-style: none;
|
|
29
|
+
&::after {
|
|
30
|
+
margin-inline-start: var(--spacing);
|
|
31
|
+
display: inline-block;
|
|
32
|
+
width: calc(var(--spacing) * 3.5);
|
|
33
|
+
height: calc(var(--spacing) * 3.5);
|
|
34
|
+
flex-shrink: 0;
|
|
35
|
+
opacity: 50%;
|
|
36
|
+
--tw-content: '';
|
|
37
|
+
content: var(--tw-content);
|
|
38
|
+
mask: var(--data-table-sort-icon) center / contain no-repeat;
|
|
39
|
+
background-color: currentColor;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
th[aria-sort='ascending'] > button::after, th[aria-sort='descending'] > button::after {
|
|
43
|
+
opacity: 100%;
|
|
44
|
+
}
|
|
45
|
+
th[aria-sort='descending'] > button::after {
|
|
46
|
+
rotate: 180deg;
|
|
47
|
+
}
|
|
48
|
+
[data-page-status], [data-selected-count] {
|
|
49
|
+
--tw-numeric-spacing: tabular-nums;
|
|
50
|
+
font-variant-numeric: var(--tw-ordinal,) var(--tw-slashed-zero,) var(--tw-numeric-figure,) var(--tw-numeric-spacing,) var(--tw-numeric-fraction,);
|
|
51
|
+
}
|
|
52
|
+
[data-selected-count] {
|
|
53
|
+
flex: 1;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@layer components {
|
|
59
|
+
.data-table {
|
|
60
|
+
gap: calc(var(--spacing) * 4);
|
|
61
|
+
}
|
|
62
|
+
.data-table > header {
|
|
63
|
+
gap: calc(var(--spacing) * 2);
|
|
64
|
+
}
|
|
65
|
+
.data-table > header > input[type='search'] {
|
|
66
|
+
max-width: var(--container-sm);
|
|
67
|
+
}
|
|
68
|
+
.data-table > div:has(> table) {
|
|
69
|
+
border-radius: var(--auvyx-r-field);
|
|
70
|
+
border-style: var(--tw-border-style);
|
|
71
|
+
border-width: 1px;
|
|
72
|
+
}
|
|
73
|
+
.data-table th[aria-sort] > button {
|
|
74
|
+
margin-inline-start: calc(var(--spacing) * -2);
|
|
75
|
+
height: calc(var(--spacing) * 8);
|
|
76
|
+
border-radius: var(--auvyx-r-control);
|
|
77
|
+
padding-inline: calc(var(--spacing) * 2);
|
|
78
|
+
&:hover {
|
|
79
|
+
@media (hover: hover) {
|
|
80
|
+
background-color: var(--color-muted);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
&:hover {
|
|
84
|
+
@media (hover: hover) {
|
|
85
|
+
color: var(--color-foreground);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
&:focus-visible {
|
|
89
|
+
--tw-ring-shadow: var(--tw-ring-inset,) 0 0 0 calc(3px + var(--tw-ring-offset-width)) var(--tw-ring-color, currentcolor);
|
|
90
|
+
box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
|
|
91
|
+
}
|
|
92
|
+
&:focus-visible {
|
|
93
|
+
--tw-ring-color: var(--color-ring);
|
|
94
|
+
@supports (color: color-mix(in lab, red, red)) {
|
|
95
|
+
--tw-ring-color: color-mix(in oklab, var(--color-ring) 50%, transparent);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
.data-table {
|
|
100
|
+
--data-table-sort-icon: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m7 15 5 5 5-5"/><path d="m7 9 5-5 5 5"/></svg>');
|
|
101
|
+
}
|
|
102
|
+
.data-table th:is([aria-sort='ascending'], [aria-sort='descending']) {
|
|
103
|
+
--data-table-sort-icon: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m5 12 7-7 7 7"/><path d="M12 19V5"/></svg>');
|
|
104
|
+
}
|
|
105
|
+
.data-table tbody tr[aria-selected='true'] {
|
|
106
|
+
background-color: var(--color-muted);
|
|
107
|
+
}
|
|
108
|
+
.data-table > footer {
|
|
109
|
+
gap: calc(var(--spacing) * 2);
|
|
110
|
+
font-size: var(--text-sm);
|
|
111
|
+
line-height: var(--tw-leading, var(--text-sm--line-height));
|
|
112
|
+
color: var(--color-muted-foreground);
|
|
113
|
+
}
|
|
114
|
+
}
|