@wcomp/elementum 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 +21 -0
- package/README.md +266 -2
- package/custom-elements.json +3613 -0
- package/mcp/server.js +408 -0
- package/package.json +72 -4
- package/skills/elementum-break-ui/CATALOG.md +11 -0
- package/skills/elementum-break-ui/SKILL.md +16 -0
- package/skills/elementum-mobile/SKILL.md +18 -0
- package/skills/elementum-motion/SKILL.md +18 -0
- package/skills/elementum-motion/STANDARDS.md +15 -0
- package/skills/elementum-penpot/SKILL.md +45 -0
- package/skills/elementum-ui/CATALOG.md +14 -0
- package/skills/elementum-ui/SKILL.md +21 -0
- package/src/ag-ui.js +474 -0
- package/src/components/el-accordion.js +201 -0
- package/src/components/el-alert-dialog.js +186 -0
- package/src/components/el-alert.js +254 -0
- package/src/components/el-aspect-ratio.js +73 -0
- package/src/components/el-autocomplete.js +775 -0
- package/src/components/el-avatar.js +271 -0
- package/src/components/el-badge.js +131 -0
- package/src/components/el-border-beam.js +135 -0
- package/src/components/el-breadcrumb.js +203 -0
- package/src/components/el-button.js +220 -0
- package/src/components/el-calendar.js +413 -0
- package/src/components/el-callout.js +158 -0
- package/src/components/el-card.js +298 -0
- package/src/components/el-carousel.js +308 -0
- package/src/components/el-chart.js +632 -0
- package/src/components/el-checkbox-card.js +221 -0
- package/src/components/el-checkbox.js +208 -0
- package/src/components/el-chip.js +276 -0
- package/src/components/el-code-block.js +228 -0
- package/src/components/el-collapsible.js +124 -0
- package/src/components/el-command.js +556 -0
- package/src/components/el-context-menu.js +328 -0
- package/src/components/el-data-list.js +210 -0
- package/src/components/el-datepicker.js +192 -0
- package/src/components/el-dialog.js +272 -0
- package/src/components/el-diff-viewer.js +441 -0
- package/src/components/el-drawer.js +782 -0
- package/src/components/el-dropdown.js +182 -0
- package/src/components/el-dropzone.js +242 -0
- package/src/components/el-empty-state.js +130 -0
- package/src/components/el-field.js +394 -0
- package/src/components/el-form.js +185 -0
- package/src/components/el-input.js +212 -0
- package/src/components/el-inset.js +90 -0
- package/src/components/el-insight-card.js +263 -0
- package/src/components/el-kbd.js +151 -0
- package/src/components/el-menubar.js +254 -0
- package/src/components/el-meter.js +182 -0
- package/src/components/el-navbar.js +294 -0
- package/src/components/el-navigation-menu.js +327 -0
- package/src/components/el-number-field.js +510 -0
- package/src/components/el-number-flow.js +153 -0
- package/src/components/el-otp-input.js +266 -0
- package/src/components/el-pagination.js +229 -0
- package/src/components/el-popover.js +288 -0
- package/src/components/el-preview-card.js +202 -0
- package/src/components/el-progress.js +179 -0
- package/src/components/el-prompt-input.js +383 -0
- package/src/components/el-radio-card.js +360 -0
- package/src/components/el-radio.js +257 -0
- package/src/components/el-rating.js +165 -0
- package/src/components/el-reasoning-card.js +293 -0
- package/src/components/el-resizable.js +324 -0
- package/src/components/el-router.js +305 -0
- package/src/components/el-scroll-area.js +150 -0
- package/src/components/el-segmented-control.js +282 -0
- package/src/components/el-select.js +219 -0
- package/src/components/el-separator.js +85 -0
- package/src/components/el-sidebar.js +386 -0
- package/src/components/el-skeleton.js +156 -0
- package/src/components/el-slider.js +351 -0
- package/src/components/el-sources.js +288 -0
- package/src/components/el-spinner.js +159 -0
- package/src/components/el-streaming-text.js +199 -0
- package/src/components/el-switch.js +221 -0
- package/src/components/el-table.js +397 -0
- package/src/components/el-tabs.js +235 -0
- package/src/components/el-task-list.js +230 -0
- package/src/components/el-textarea.js +175 -0
- package/src/components/el-theme-switch.js +120 -0
- package/src/components/el-timeline.js +254 -0
- package/src/components/el-toast.js +778 -0
- package/src/components/el-toggle.js +311 -0
- package/src/components/el-tool-call.js +386 -0
- package/src/components/el-toolbar.js +183 -0
- package/src/components/el-tooltip.js +172 -0
- package/src/components/el-tree-view.js +261 -0
- package/src/components/el-visually-hidden.js +32 -0
- package/src/elementum.js +485 -0
- package/src/index.d.ts +1007 -0
- package/src/index.js +99 -0
- package/src/signal.js +194 -0
- package/src/ssr.js +136 -0
- package/src/template.js +321 -0
- package/src/tokens.css +416 -0
- package/tokens/figma-tokens.json +69 -0
- package/tokens/penpot-tokens.json +98 -0
|
@@ -0,0 +1,556 @@
|
|
|
1
|
+
import { Elementum } from '../elementum.js';
|
|
2
|
+
import { html, css } from '../template.js';
|
|
3
|
+
import { signal, effect } from '../signal.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* <el-command-item>
|
|
7
|
+
* Individual actionable item within <el-command>.
|
|
8
|
+
*/
|
|
9
|
+
export class ElCommandItem extends Elementum {
|
|
10
|
+
static observedAttributes = ['value', 'shortcut', 'disabled'];
|
|
11
|
+
|
|
12
|
+
value = signal('');
|
|
13
|
+
shortcut = signal('');
|
|
14
|
+
disabled = signal(false);
|
|
15
|
+
active = signal(false);
|
|
16
|
+
|
|
17
|
+
connected() {
|
|
18
|
+
this.setAttribute('role', 'option');
|
|
19
|
+
if (!this.id) {
|
|
20
|
+
this.id = `cmd-item-${Math.random().toString(36).slice(2, 8)}`;
|
|
21
|
+
}
|
|
22
|
+
this.setAttribute('aria-selected', 'false');
|
|
23
|
+
this.value.value = this.getAttribute('value') || this.textContent.trim();
|
|
24
|
+
this.shortcut.value = this.getAttribute('shortcut') || '';
|
|
25
|
+
this.disabled.value = this.hasAttribute('disabled');
|
|
26
|
+
if (this.disabled.value) {
|
|
27
|
+
this.setAttribute('aria-disabled', 'true');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
attributeChanged(name, oldValue, newValue) {
|
|
32
|
+
if (name === 'value') {
|
|
33
|
+
this.value.value = newValue || this.textContent.trim();
|
|
34
|
+
} else if (name === 'shortcut') {
|
|
35
|
+
this.shortcut.value = newValue || '';
|
|
36
|
+
} else if (name === 'disabled') {
|
|
37
|
+
this.disabled.value = newValue !== null && newValue !== 'false';
|
|
38
|
+
if (this.disabled.value) {
|
|
39
|
+
this.setAttribute('aria-disabled', 'true');
|
|
40
|
+
} else {
|
|
41
|
+
this.removeAttribute('aria-disabled');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static styles = css`
|
|
47
|
+
:host {
|
|
48
|
+
display: flex;
|
|
49
|
+
align-items: center;
|
|
50
|
+
justify-content: space-between;
|
|
51
|
+
padding: 10px 14px;
|
|
52
|
+
border-radius: var(--el-radius-md, 8px);
|
|
53
|
+
cursor: pointer;
|
|
54
|
+
font-size: 0.875rem;
|
|
55
|
+
color: var(--el-text-primary, #0f172a);
|
|
56
|
+
transition: background-color 0.1s ease, color 0.1s ease;
|
|
57
|
+
user-select: none;
|
|
58
|
+
box-sizing: border-box;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
:host(:hover),
|
|
62
|
+
:host([data-active="true"]) {
|
|
63
|
+
background-color: var(--el-surface-muted, #f1f5f9);
|
|
64
|
+
color: var(--el-color-primary, #2563eb);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
:host([disabled]) {
|
|
68
|
+
opacity: 0.5;
|
|
69
|
+
cursor: not-allowed;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.item-content {
|
|
73
|
+
display: inline-flex;
|
|
74
|
+
align-items: center;
|
|
75
|
+
gap: 10px;
|
|
76
|
+
flex: 1;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.shortcut {
|
|
80
|
+
display: inline-flex;
|
|
81
|
+
align-items: center;
|
|
82
|
+
gap: 4px;
|
|
83
|
+
font-size: 0.75rem;
|
|
84
|
+
font-family: var(--el-font-mono, monospace);
|
|
85
|
+
color: var(--el-text-muted, #64748b);
|
|
86
|
+
background: var(--el-surface-muted, #e2e8f0);
|
|
87
|
+
padding: 2px 6px;
|
|
88
|
+
border-radius: 4px;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@media (prefers-reduced-motion: reduce) {
|
|
92
|
+
*, *::before, *::after {
|
|
93
|
+
animation: none !important;
|
|
94
|
+
transition: none !important;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
`;
|
|
98
|
+
|
|
99
|
+
render() {
|
|
100
|
+
return html`
|
|
101
|
+
<div class="item-content" part="content">
|
|
102
|
+
<slot></slot>
|
|
103
|
+
</div>
|
|
104
|
+
${() => this.shortcut.value ? html`<span class="shortcut" part="shortcut">${this.shortcut.value}</span>` : null}
|
|
105
|
+
`;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* <el-command-group>
|
|
111
|
+
* Category section within <el-command>.
|
|
112
|
+
*/
|
|
113
|
+
export class ElCommandGroup extends Elementum {
|
|
114
|
+
static observedAttributes = ['heading'];
|
|
115
|
+
static #count = 0;
|
|
116
|
+
|
|
117
|
+
heading = signal('');
|
|
118
|
+
#headingId = '';
|
|
119
|
+
|
|
120
|
+
connected() {
|
|
121
|
+
this.setAttribute('role', 'group');
|
|
122
|
+
this.heading.value = this.getAttribute('heading') || '';
|
|
123
|
+
this.#headingId = `cmd-grp-${++ElCommandGroup.#count}`;
|
|
124
|
+
this.setAttribute('aria-labelledby', this.#headingId);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
attributeChanged(name, oldValue, newValue) {
|
|
128
|
+
if (name === 'heading') {
|
|
129
|
+
this.heading.value = newValue || '';
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
static styles = css`
|
|
134
|
+
:host {
|
|
135
|
+
display: block;
|
|
136
|
+
margin-bottom: 12px;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.heading {
|
|
140
|
+
padding: 6px 12px;
|
|
141
|
+
font-size: 0.75rem;
|
|
142
|
+
font-weight: 700;
|
|
143
|
+
text-transform: uppercase;
|
|
144
|
+
letter-spacing: 0.05em;
|
|
145
|
+
color: var(--el-text-muted, #64748b);
|
|
146
|
+
}
|
|
147
|
+
`;
|
|
148
|
+
|
|
149
|
+
render() {
|
|
150
|
+
return html`
|
|
151
|
+
${() => this.heading.value ? html`<div class="heading" id=${this.#headingId} part="heading">${this.heading.value}</div>` : null}
|
|
152
|
+
<div class="items" part="items">
|
|
153
|
+
<slot></slot>
|
|
154
|
+
</div>
|
|
155
|
+
`;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* <el-command>
|
|
161
|
+
* Accessible command palette dialog (⌘K / cmdk style).
|
|
162
|
+
*
|
|
163
|
+
* @attr {string} placeholder - Search placeholder
|
|
164
|
+
* @fires select - Dispatched when an item is selected with { value, item }
|
|
165
|
+
*/
|
|
166
|
+
export class ElCommand extends Elementum {
|
|
167
|
+
static observedAttributes = ['placeholder', 'open', 'inline', 'disabled'];
|
|
168
|
+
|
|
169
|
+
placeholder = signal('Type a command or search...');
|
|
170
|
+
isOpen = signal(false);
|
|
171
|
+
inline = signal(false);
|
|
172
|
+
disabled = signal(false);
|
|
173
|
+
query = signal('');
|
|
174
|
+
activeIndex = signal(0);
|
|
175
|
+
#emptyVisible = signal(false);
|
|
176
|
+
#previouslyFocused = null;
|
|
177
|
+
|
|
178
|
+
get open() {
|
|
179
|
+
return this.isOpen;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
set open(v) {
|
|
183
|
+
this.isOpen.value = Boolean(v);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
connected() {
|
|
187
|
+
if (this.hasAttribute('placeholder')) this.placeholder.value = this.getAttribute('placeholder');
|
|
188
|
+
if (this.hasAttribute('open') && this.getAttribute('open') !== 'false') this.isOpen.value = true;
|
|
189
|
+
if (this.hasAttribute('inline') && this.getAttribute('inline') !== 'false') this.inline.value = true;
|
|
190
|
+
if (this.hasAttribute('disabled') && this.getAttribute('disabled') !== 'false') this.disabled.value = true;
|
|
191
|
+
|
|
192
|
+
// Global keyboard shortcut: Cmd+K / Ctrl+K
|
|
193
|
+
const onGlobalKey = (e) => {
|
|
194
|
+
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k') {
|
|
195
|
+
e.preventDefault();
|
|
196
|
+
this.toggle();
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
window.addEventListener('keydown', onGlobalKey, { signal: this.signal });
|
|
200
|
+
this.addEventListener('keydown', this.#onKeyDown, { signal: this.signal });
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
attributeChanged(name, oldValue, newValue) {
|
|
204
|
+
if (name === 'open') {
|
|
205
|
+
const shouldOpen = newValue !== null && newValue !== 'false';
|
|
206
|
+
if (shouldOpen) this.show();
|
|
207
|
+
else this.close();
|
|
208
|
+
} else if (name === 'placeholder') {
|
|
209
|
+
this.placeholder.value = newValue || 'Type a command or search...';
|
|
210
|
+
} else if (name === 'inline') {
|
|
211
|
+
this.inline.value = newValue !== null && newValue !== 'false';
|
|
212
|
+
} else if (name === 'disabled') {
|
|
213
|
+
this.disabled.value = newValue !== null && newValue !== 'false';
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
static styles = css`
|
|
218
|
+
:host {
|
|
219
|
+
display: contents;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
:host([inline]) {
|
|
223
|
+
display: block;
|
|
224
|
+
width: 100%;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
.command-backdrop {
|
|
228
|
+
position: fixed;
|
|
229
|
+
inset: 0;
|
|
230
|
+
background: rgba(15, 23, 42, 0.45);
|
|
231
|
+
backdrop-filter: blur(4px);
|
|
232
|
+
z-index: 9999;
|
|
233
|
+
display: none;
|
|
234
|
+
align-items: flex-start;
|
|
235
|
+
justify-content: center;
|
|
236
|
+
padding: 15vh 16px 16px;
|
|
237
|
+
box-sizing: border-box;
|
|
238
|
+
animation: fadeIn 0.15s ease-out;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
:host([inline]) .command-backdrop {
|
|
242
|
+
position: relative;
|
|
243
|
+
inset: auto;
|
|
244
|
+
background: transparent;
|
|
245
|
+
backdrop-filter: none;
|
|
246
|
+
z-index: 1;
|
|
247
|
+
display: flex;
|
|
248
|
+
padding: 0;
|
|
249
|
+
animation: none;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
:host([disabled]) .command-dialog {
|
|
253
|
+
opacity: 0.6;
|
|
254
|
+
pointer-events: none;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
@media (max-width: 640px) {
|
|
258
|
+
.command-backdrop {
|
|
259
|
+
padding: 32px 12px 12px;
|
|
260
|
+
}
|
|
261
|
+
.command-dialog {
|
|
262
|
+
max-width: 100%;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
.command-backdrop.open {
|
|
267
|
+
display: flex;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
.command-dialog {
|
|
271
|
+
width: 100%;
|
|
272
|
+
max-width: 620px;
|
|
273
|
+
background: var(--el-surface-card, #ffffff);
|
|
274
|
+
border: 1px solid var(--el-border-translucent, rgba(15, 23, 42, 0.08));
|
|
275
|
+
border-radius: var(--el-radius-lg, 12px);
|
|
276
|
+
box-shadow: var(--el-shadow-popover, 0 20px 25px -5px rgba(0, 0, 0, 0.1));
|
|
277
|
+
overflow: hidden;
|
|
278
|
+
display: flex;
|
|
279
|
+
flex-direction: column;
|
|
280
|
+
animation: scaleUp 0.15s cubic-bezier(0.16, 1, 0.3, 1);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
.search-bar {
|
|
284
|
+
display: flex;
|
|
285
|
+
align-items: center;
|
|
286
|
+
padding: 0 16px;
|
|
287
|
+
border-bottom: 1px solid var(--el-surface-border, #e2e8f0);
|
|
288
|
+
min-height: 52px;
|
|
289
|
+
gap: 12px;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
.search-icon {
|
|
293
|
+
font-size: 1.125rem;
|
|
294
|
+
color: var(--el-text-muted, #64748b);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
.search-input {
|
|
298
|
+
flex: 1;
|
|
299
|
+
border: none;
|
|
300
|
+
background: transparent;
|
|
301
|
+
outline: none;
|
|
302
|
+
font-family: inherit;
|
|
303
|
+
font-size: 1rem;
|
|
304
|
+
color: var(--el-text-primary, #0f172a);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
.command-list {
|
|
308
|
+
max-height: 340px;
|
|
309
|
+
overflow-y: auto;
|
|
310
|
+
padding: 8px;
|
|
311
|
+
box-sizing: border-box;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
.empty-state {
|
|
315
|
+
padding: 24px;
|
|
316
|
+
text-align: center;
|
|
317
|
+
font-size: 0.875rem;
|
|
318
|
+
color: var(--el-text-muted, #64748b);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
.command-footer {
|
|
322
|
+
display: flex;
|
|
323
|
+
align-items: center;
|
|
324
|
+
justify-content: space-between;
|
|
325
|
+
padding: 8px 16px;
|
|
326
|
+
background: var(--el-surface-muted, #f8fafc);
|
|
327
|
+
border-top: 1px solid var(--el-surface-border, #e2e8f0);
|
|
328
|
+
font-size: 0.75rem;
|
|
329
|
+
color: var(--el-text-muted, #64748b);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
.footer-keys {
|
|
333
|
+
display: inline-flex;
|
|
334
|
+
gap: 8px;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
@keyframes fadeIn {
|
|
338
|
+
from { opacity: 0; }
|
|
339
|
+
to { opacity: 1; }
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
@keyframes scaleUp {
|
|
343
|
+
from { transform: scale(0.96) translateY(-8px); opacity: 0; }
|
|
344
|
+
to { transform: scale(1) translateY(0); opacity: 1; }
|
|
345
|
+
}
|
|
346
|
+
`;
|
|
347
|
+
|
|
348
|
+
show() {
|
|
349
|
+
this.#previouslyFocused = typeof document !== 'undefined' ? document.activeElement : null;
|
|
350
|
+
this.isOpen.value = true;
|
|
351
|
+
this.query.value = '';
|
|
352
|
+
this.activeIndex.value = 0;
|
|
353
|
+
this.#emptyVisible.value = false;
|
|
354
|
+
setTimeout(() => {
|
|
355
|
+
this.root?.querySelector('.search-input')?.focus();
|
|
356
|
+
this.#filterItems('');
|
|
357
|
+
}, 50);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
close() {
|
|
361
|
+
this.isOpen.value = false;
|
|
362
|
+
if (this.#previouslyFocused && typeof this.#previouslyFocused.focus === 'function') {
|
|
363
|
+
this.#previouslyFocused.focus();
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
toggle() {
|
|
368
|
+
if (this.isOpen.value) this.close();
|
|
369
|
+
else this.show();
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
#onSearchInput = (e) => {
|
|
373
|
+
const q = e.target.value;
|
|
374
|
+
this.query.value = q;
|
|
375
|
+
this.activeIndex.value = 0;
|
|
376
|
+
this.#filterItems(q);
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
#filterItems(query) {
|
|
380
|
+
const q = query.trim().toLowerCase();
|
|
381
|
+
const items = Array.from(this.querySelectorAll('el-command-item'));
|
|
382
|
+
const groups = Array.from(this.querySelectorAll('el-command-group'));
|
|
383
|
+
|
|
384
|
+
let visibleCount = 0;
|
|
385
|
+
items.forEach((item) => {
|
|
386
|
+
const text = item.textContent.trim().toLowerCase();
|
|
387
|
+
const val = (item.getAttribute('value') || '').toLowerCase();
|
|
388
|
+
const match = text.includes(q) || val.includes(q);
|
|
389
|
+
item.style.display = match ? 'flex' : 'none';
|
|
390
|
+
if (match) visibleCount++;
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
// Hide groups if no children visible
|
|
394
|
+
groups.forEach((group) => {
|
|
395
|
+
const visibleChildren = group.querySelectorAll('el-command-item:not([style*="display: none"])');
|
|
396
|
+
group.style.display = visibleChildren.length > 0 ? 'block' : 'none';
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
this.#emptyVisible.value = visibleCount === 0;
|
|
400
|
+
this.#updateActiveHighlight();
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
#getVisibleItems() {
|
|
404
|
+
return Array.from(this.querySelectorAll('el-command-item')).filter(
|
|
405
|
+
(it) => it.style.display !== 'none' && !it.hasAttribute('disabled')
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
#updateActiveHighlight() {
|
|
410
|
+
const visible = this.#getVisibleItems();
|
|
411
|
+
const input = this.root?.querySelector('.search-input');
|
|
412
|
+
visible.forEach((it, idx) => {
|
|
413
|
+
if (idx === this.activeIndex.value) {
|
|
414
|
+
it.setAttribute('data-active', 'true');
|
|
415
|
+
it.setAttribute('aria-selected', 'true');
|
|
416
|
+
it.active.value = true;
|
|
417
|
+
if (!it.id) {
|
|
418
|
+
it.id = `cmd-item-${idx}-${Math.random().toString(36).slice(2, 6)}`;
|
|
419
|
+
}
|
|
420
|
+
input?.setAttribute('aria-activedescendant', it.id);
|
|
421
|
+
if (typeof it.scrollIntoView === 'function') {
|
|
422
|
+
it.scrollIntoView({ block: 'nearest' });
|
|
423
|
+
}
|
|
424
|
+
} else {
|
|
425
|
+
it.removeAttribute('data-active');
|
|
426
|
+
it.setAttribute('aria-selected', 'false');
|
|
427
|
+
it.active.value = false;
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
if (visible.length === 0) {
|
|
432
|
+
input?.removeAttribute('aria-activedescendant');
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
#onKeyDown = (e) => {
|
|
437
|
+
if (!this.isOpen.value && !this.inline.value) return;
|
|
438
|
+
const visible = this.#getVisibleItems();
|
|
439
|
+
|
|
440
|
+
switch (e.key) {
|
|
441
|
+
case 'ArrowDown':
|
|
442
|
+
e.preventDefault();
|
|
443
|
+
if (visible.length > 0) {
|
|
444
|
+
this.activeIndex.value = (this.activeIndex.value + 1) % visible.length;
|
|
445
|
+
this.#updateActiveHighlight();
|
|
446
|
+
}
|
|
447
|
+
break;
|
|
448
|
+
|
|
449
|
+
case 'ArrowUp':
|
|
450
|
+
e.preventDefault();
|
|
451
|
+
if (visible.length > 0) {
|
|
452
|
+
this.activeIndex.value = (this.activeIndex.value - 1 + visible.length) % visible.length;
|
|
453
|
+
this.#updateActiveHighlight();
|
|
454
|
+
}
|
|
455
|
+
break;
|
|
456
|
+
|
|
457
|
+
case 'Enter':
|
|
458
|
+
e.preventDefault();
|
|
459
|
+
if (visible.length > 0 && visible[this.activeIndex.value]) {
|
|
460
|
+
this.#selectItem(visible[this.activeIndex.value]);
|
|
461
|
+
}
|
|
462
|
+
break;
|
|
463
|
+
|
|
464
|
+
case 'Escape':
|
|
465
|
+
e.preventDefault();
|
|
466
|
+
this.close();
|
|
467
|
+
break;
|
|
468
|
+
|
|
469
|
+
case 'Tab':
|
|
470
|
+
// Trap focus inside modal
|
|
471
|
+
e.preventDefault();
|
|
472
|
+
break;
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
#selectItem(item) {
|
|
477
|
+
const val = item.getAttribute('value') || item.textContent.trim();
|
|
478
|
+
this.close();
|
|
479
|
+
this.emit('select', { value: val, item });
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
render() {
|
|
483
|
+
return html`
|
|
484
|
+
<div
|
|
485
|
+
class=${() => `command-backdrop ${this.isOpen.value ? 'open' : ''}`}
|
|
486
|
+
part="backdrop"
|
|
487
|
+
@click=${(e) => { if (e.target === e.currentTarget) this.close(); }}
|
|
488
|
+
>
|
|
489
|
+
<div
|
|
490
|
+
class="command-dialog"
|
|
491
|
+
part="dialog"
|
|
492
|
+
role="dialog"
|
|
493
|
+
aria-modal="true"
|
|
494
|
+
aria-label="Command Menu"
|
|
495
|
+
>
|
|
496
|
+
<div class="search-bar" part="search-bar">
|
|
497
|
+
<span class="search-icon" aria-hidden="true">🔍</span>
|
|
498
|
+
<input
|
|
499
|
+
type="text"
|
|
500
|
+
class="search-input"
|
|
501
|
+
part="input"
|
|
502
|
+
role="combobox"
|
|
503
|
+
aria-autocomplete="list"
|
|
504
|
+
aria-expanded=${() => String(this.isOpen.value)}
|
|
505
|
+
aria-controls="cmd-listbox"
|
|
506
|
+
aria-haspopup="listbox"
|
|
507
|
+
placeholder=${this.placeholder}
|
|
508
|
+
.value=${this.query}
|
|
509
|
+
@input=${this.#onSearchInput}
|
|
510
|
+
/>
|
|
511
|
+
</div>
|
|
512
|
+
|
|
513
|
+
<div
|
|
514
|
+
id="cmd-listbox"
|
|
515
|
+
class="command-list"
|
|
516
|
+
part="list"
|
|
517
|
+
role="listbox"
|
|
518
|
+
aria-label="Commands"
|
|
519
|
+
@click=${(e) => {
|
|
520
|
+
const item = e.target.closest('el-command-item');
|
|
521
|
+
if (item && !item.hasAttribute('disabled')) {
|
|
522
|
+
this.#selectItem(item);
|
|
523
|
+
}
|
|
524
|
+
}}
|
|
525
|
+
>
|
|
526
|
+
<slot></slot>
|
|
527
|
+
<div
|
|
528
|
+
class="empty-state"
|
|
529
|
+
part="empty"
|
|
530
|
+
role="status"
|
|
531
|
+
aria-live="polite"
|
|
532
|
+
style=${() => this.#emptyVisible.value ? 'display: block;' : 'display: none;'}
|
|
533
|
+
>
|
|
534
|
+
No commands or actions found.
|
|
535
|
+
</div>
|
|
536
|
+
</div>
|
|
537
|
+
|
|
538
|
+
<div class="command-footer" part="footer">
|
|
539
|
+
<span>Navigation</span>
|
|
540
|
+
<div class="footer-keys">
|
|
541
|
+
<span><kbd>↑</kbd><kbd>↓</kbd> navigate</span>
|
|
542
|
+
<span><kbd>↵</kbd> select</span>
|
|
543
|
+
<span><kbd>esc</kbd> close</span>
|
|
544
|
+
</div>
|
|
545
|
+
</div>
|
|
546
|
+
</div>
|
|
547
|
+
</div>
|
|
548
|
+
`;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
if (typeof customElements !== 'undefined') {
|
|
553
|
+
if (!customElements.get('el-command-item')) customElements.define('el-command-item', ElCommandItem);
|
|
554
|
+
if (!customElements.get('el-command-group')) customElements.define('el-command-group', ElCommandGroup);
|
|
555
|
+
if (!customElements.get('el-command')) customElements.define('el-command', ElCommand);
|
|
556
|
+
}
|