@adia-ai/web-components 0.6.33 → 0.6.34
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/CHANGELOG.md +22 -0
- package/components/accordion/accordion.css +2 -2
- package/components/action-list/action-list.css +2 -2
- package/components/agent-artifact/agent-artifact.css +31 -31
- package/components/agent-feedback-bar/agent-feedback-bar.css +10 -10
- package/components/agent-questions/agent-questions.css +57 -57
- package/components/agent-reasoning/agent-reasoning.css +62 -62
- package/components/agent-suggestions/agent-suggestions.css +4 -4
- package/components/agent-trace/agent-trace.css +53 -53
- package/components/alert/alert.css +41 -41
- package/components/avatar/avatar.css +27 -27
- package/components/badge/badge.css +27 -27
- package/components/block/block.css +16 -16
- package/components/breadcrumb/breadcrumb.css +23 -23
- package/components/button/button.css +101 -91
- package/components/calendar-grid/calendar-grid.a2ui.json +136 -0
- package/components/calendar-grid/calendar-grid.css +226 -0
- package/components/calendar-grid/calendar-grid.d.ts +37 -0
- package/components/calendar-grid/calendar-grid.js +17 -0
- package/components/calendar-grid/calendar-grid.yaml +116 -0
- package/components/calendar-grid/class.js +300 -0
- package/components/calendar-picker/calendar-picker.css +139 -139
- package/components/canvas/canvas.css +12 -12
- package/components/card/card.css +83 -83
- package/components/chart/chart.css +224 -224
- package/components/chart-legend/chart-legend.css +26 -26
- package/components/check/check.css +40 -40
- package/components/code/code.css +125 -125
- package/components/col/col.css +15 -15
- package/components/color-picker/color-picker.css +55 -55
- package/components/combobox/class.js +861 -0
- package/components/combobox/combobox.a2ui.json +363 -0
- package/components/combobox/combobox.css +244 -0
- package/components/combobox/combobox.d.ts +113 -0
- package/components/combobox/combobox.examples.md +59 -0
- package/components/combobox/combobox.js +17 -0
- package/components/combobox/combobox.test.js +181 -0
- package/components/combobox/combobox.yaml +369 -0
- package/components/command/command.css +90 -90
- package/components/date-range-picker/class.js +775 -0
- package/components/date-range-picker/date-range-picker.a2ui.json +300 -0
- package/components/date-range-picker/date-range-picker.css +178 -0
- package/components/date-range-picker/date-range-picker.d.ts +82 -0
- package/components/date-range-picker/date-range-picker.examples.md +37 -0
- package/components/date-range-picker/date-range-picker.js +17 -0
- package/components/date-range-picker/date-range-picker.test.js +387 -0
- package/components/date-range-picker/date-range-picker.yaml +285 -0
- package/components/datetime-picker/class.js +706 -0
- package/components/datetime-picker/datetime-picker.a2ui.json +334 -0
- package/components/datetime-picker/datetime-picker.css +150 -0
- package/components/datetime-picker/datetime-picker.d.ts +86 -0
- package/components/datetime-picker/datetime-picker.examples.md +46 -0
- package/components/datetime-picker/datetime-picker.js +17 -0
- package/components/datetime-picker/datetime-picker.test.js +454 -0
- package/components/datetime-picker/datetime-picker.yaml +332 -0
- package/components/demo-toggle/demo-toggle.css +27 -27
- package/components/description-list/description-list.css +18 -18
- package/components/divider/divider.css +24 -24
- package/components/embed/embed.css +6 -6
- package/components/empty-state/empty-state.css +27 -27
- package/components/feed/feed.css +12 -12
- package/components/field/field.css +28 -28
- package/components/fields/fields.css +5 -5
- package/components/grid/grid.css +5 -5
- package/components/heatmap/heatmap.css +63 -63
- package/components/icon/icon.css +12 -12
- package/components/image/image.css +14 -14
- package/components/index.js +8 -0
- package/components/input/input.css +66 -66
- package/components/inspector/inspector.css +6 -6
- package/components/integration-card/class.js +410 -0
- package/components/integration-card/integration-card.a2ui.json +268 -0
- package/components/integration-card/integration-card.css +169 -0
- package/components/integration-card/integration-card.d.ts +63 -0
- package/components/integration-card/integration-card.examples.md +41 -0
- package/components/integration-card/integration-card.js +17 -0
- package/components/integration-card/integration-card.test.js +306 -0
- package/components/integration-card/integration-card.yaml +280 -0
- package/components/kbd/kbd.css +32 -32
- package/components/link/link.css +12 -12
- package/components/list/list.css +8 -8
- package/components/list-window/class.js +688 -0
- package/components/list-window/list-window.a2ui.json +277 -0
- package/components/list-window/list-window.css +124 -0
- package/components/list-window/list-window.d.ts +84 -0
- package/components/list-window/list-window.examples.md +73 -0
- package/components/list-window/list-window.js +17 -0
- package/components/list-window/list-window.test.js +303 -0
- package/components/list-window/list-window.yaml +270 -0
- package/components/menu/menu.css +8 -8
- package/components/modal/modal.css +43 -43
- package/components/nav/nav.css +40 -40
- package/components/nav-group/nav-group.css +52 -52
- package/components/nav-item/nav-item.css +44 -44
- package/components/noodles/noodles.css +31 -31
- package/components/option-card/option-card.css +69 -69
- package/components/otp-input/otp-input.css +30 -30
- package/components/page/page.css +18 -18
- package/components/pagination/pagination.css +61 -61
- package/components/pane/pane.css +57 -57
- package/components/pipeline-status/pipeline-status.css +65 -65
- package/components/popover/popover.css +17 -17
- package/components/progress/progress.css +23 -23
- package/components/progress-row/progress-row.css +17 -17
- package/components/radio/radio.css +39 -39
- package/components/range/range.css +55 -55
- package/components/rating/rating.css +28 -28
- package/components/richtext/richtext.css +133 -133
- package/components/row/row.css +19 -19
- package/components/search/search.css +5 -5
- package/components/segment/segment.css +24 -24
- package/components/segmented/segmented.css +25 -25
- package/components/select/select.css +84 -84
- package/components/skeleton/skeleton.css +14 -14
- package/components/slider/slider.css +46 -46
- package/components/spinner/class.js +69 -0
- package/components/spinner/spinner.a2ui.json +197 -0
- package/components/spinner/spinner.css +165 -0
- package/components/spinner/spinner.d.ts +26 -0
- package/components/spinner/spinner.examples.md +26 -0
- package/components/spinner/spinner.js +17 -0
- package/components/spinner/spinner.test.js +234 -0
- package/components/spinner/spinner.yaml +230 -0
- package/components/stack/stack.css +11 -11
- package/components/stat/stat.css +25 -25
- package/components/step-progress/step-progress.css +20 -20
- package/components/stepper/stepper.css +29 -29
- package/components/stream/stream.css +12 -12
- package/components/swatch/swatch.css +68 -68
- package/components/swiper/swiper.css +57 -57
- package/components/switch/switch.css +52 -52
- package/components/table/table.css +162 -162
- package/components/table-toolbar/table-toolbar.css +32 -32
- package/components/tabs/tabs.css +51 -51
- package/components/tag/tag.css +48 -48
- package/components/text/text.css +44 -44
- package/components/textarea/textarea.css +46 -46
- package/components/time-picker/class.js +693 -0
- package/components/time-picker/time-picker.a2ui.json +267 -0
- package/components/time-picker/time-picker.css +122 -0
- package/components/time-picker/time-picker.d.ts +75 -0
- package/components/time-picker/time-picker.examples.md +35 -0
- package/components/time-picker/time-picker.js +17 -0
- package/components/time-picker/time-picker.test.js +287 -0
- package/components/time-picker/time-picker.yaml +256 -0
- package/components/timeline/timeline.css +50 -50
- package/components/toast/toast.css +58 -58
- package/components/toggle-group/toggle-group.css +6 -6
- package/components/toggle-scheme/toggle-scheme.css +2 -2
- package/components/toolbar/toolbar.css +17 -17
- package/components/tooltip/tooltip.css +2 -2
- package/components/tree/tree.css +37 -37
- package/components/upload/upload.css +49 -49
- package/dist/web-components.min.css +1 -1
- package/dist/web-components.min.js +121 -83
- package/package.json +1 -1
- package/styles/components.css +8 -0
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <list-window-ui> — virtualization / windowing tests.
|
|
3
|
+
*
|
|
4
|
+
* Coverage scope (per SPEC-022 §11 Verification):
|
|
5
|
+
*
|
|
6
|
+
* - empty items[] → [empty] state attribute set; window collapsed
|
|
7
|
+
* - fixed-size mode: ≤ (viewport / item-size) + 2*overscan DOM rows
|
|
8
|
+
* - 10_000 items: still ≤ 50 DOM rows
|
|
9
|
+
* - scroll re-emits `range-change` with new start/end indices
|
|
10
|
+
* - scrollToIndex() lands the row in the visible window
|
|
11
|
+
* - pin-bottom keeps scroll at the bottom on append
|
|
12
|
+
* - removing an item updates total scroll height
|
|
13
|
+
* - key-fn preserves DOM nodes across items[] reorder
|
|
14
|
+
* - aria-rowcount reflects full items.length
|
|
15
|
+
* - skeleton loading state replaces real rows
|
|
16
|
+
*
|
|
17
|
+
* happy-dom doesn't lay out elements (clientHeight is 0 by default),
|
|
18
|
+
* so we set the host's clientHeight via a clientHeight-stub. The
|
|
19
|
+
* windowing math runs deterministically against that stub.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
23
|
+
import './list-window.js';
|
|
24
|
+
|
|
25
|
+
const tick = () => new Promise((r) => queueMicrotask(r));
|
|
26
|
+
const wait = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
27
|
+
|
|
28
|
+
/** Stub the host's clientHeight + clientWidth so range computation can
|
|
29
|
+
* run inside happy-dom. The virtualization math reads `this.clientHeight`
|
|
30
|
+
* (vertical mode) — without a stub it's always 0 and range collapses. */
|
|
31
|
+
function stubViewport(el, { height = 400, width = 400 } = {}) {
|
|
32
|
+
Object.defineProperty(el, 'clientHeight', { value: height, configurable: true });
|
|
33
|
+
Object.defineProperty(el, 'clientWidth', { value: width, configurable: true });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Build N items with a stable shape for tests. */
|
|
37
|
+
function makeItems(n) {
|
|
38
|
+
return Array.from({ length: n }, (_, i) => ({ id: `i-${i}`, text: `Item ${i}` }));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
describe('<list-window-ui>', () => {
|
|
42
|
+
beforeEach(() => { document.body.innerHTML = ''; });
|
|
43
|
+
afterEach(() => { document.body.innerHTML = ''; });
|
|
44
|
+
|
|
45
|
+
it('shows [empty] state when items.length === 0', async () => {
|
|
46
|
+
const el = document.createElement('list-window-ui');
|
|
47
|
+
el.setAttribute('item-size', '48');
|
|
48
|
+
stubViewport(el);
|
|
49
|
+
document.body.appendChild(el);
|
|
50
|
+
el.items = [];
|
|
51
|
+
await tick();
|
|
52
|
+
expect(el.hasAttribute('empty')).toBe(true);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('sets aria-rowcount to the full items.length (not the windowed count)', async () => {
|
|
56
|
+
const el = document.createElement('list-window-ui');
|
|
57
|
+
el.setAttribute('item-size', '48');
|
|
58
|
+
stubViewport(el, { height: 400 });
|
|
59
|
+
document.body.appendChild(el);
|
|
60
|
+
el.items = makeItems(1000);
|
|
61
|
+
await tick();
|
|
62
|
+
expect(el.getAttribute('aria-rowcount')).toBe('1000');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('materializes only ~viewport-worth of rows, not all 1000', async () => {
|
|
66
|
+
const el = document.createElement('list-window-ui');
|
|
67
|
+
el.setAttribute('item-size', '48');
|
|
68
|
+
stubViewport(el, { height: 400 }); // 400 / 48 ≈ 9 visible rows
|
|
69
|
+
document.body.appendChild(el);
|
|
70
|
+
el.overscan = 3;
|
|
71
|
+
el.items = makeItems(1000);
|
|
72
|
+
await tick();
|
|
73
|
+
const rows = el.querySelectorAll('[data-window] > [data-row]');
|
|
74
|
+
// ~9 visible + 2*3 overscan = ~15; tolerate ≤ 30 for happy-dom jitter
|
|
75
|
+
expect(rows.length).toBeGreaterThan(0);
|
|
76
|
+
expect(rows.length).toBeLessThanOrEqual(30);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('still materializes ≤ 50 DOM rows for items.length === 10_000', async () => {
|
|
80
|
+
const el = document.createElement('list-window-ui');
|
|
81
|
+
el.setAttribute('item-size', '48');
|
|
82
|
+
stubViewport(el, { height: 400 });
|
|
83
|
+
document.body.appendChild(el);
|
|
84
|
+
el.overscan = 5;
|
|
85
|
+
el.items = makeItems(10_000);
|
|
86
|
+
await tick();
|
|
87
|
+
const rows = el.querySelectorAll('[data-window] > [data-row]');
|
|
88
|
+
expect(rows.length).toBeGreaterThan(0);
|
|
89
|
+
expect(rows.length).toBeLessThanOrEqual(50);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('phantom spacer total height = items.length * item-size (fixed mode)', async () => {
|
|
93
|
+
const el = document.createElement('list-window-ui');
|
|
94
|
+
el.setAttribute('item-size', '48');
|
|
95
|
+
stubViewport(el, { height: 400 });
|
|
96
|
+
document.body.appendChild(el);
|
|
97
|
+
el.items = makeItems(1000);
|
|
98
|
+
await tick();
|
|
99
|
+
const phantom = el.querySelector('[data-phantom]');
|
|
100
|
+
expect(phantom).not.toBeNull();
|
|
101
|
+
expect(phantom.style.height).toBe('48000px');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('scrollToIndex(500) updates the visible range to include 500', async () => {
|
|
105
|
+
const el = document.createElement('list-window-ui');
|
|
106
|
+
el.setAttribute('item-size', '48');
|
|
107
|
+
stubViewport(el, { height: 400 });
|
|
108
|
+
document.body.appendChild(el);
|
|
109
|
+
el.items = makeItems(1000);
|
|
110
|
+
await tick();
|
|
111
|
+
|
|
112
|
+
// Stub scrollTo + scrollTop so happy-dom honours the assignment.
|
|
113
|
+
let stubbedScrollTop = 0;
|
|
114
|
+
Object.defineProperty(el, 'scrollTop', {
|
|
115
|
+
get() { return stubbedScrollTop; },
|
|
116
|
+
set(v) { stubbedScrollTop = v; },
|
|
117
|
+
configurable: true,
|
|
118
|
+
});
|
|
119
|
+
el.scrollTo = (opts) => {
|
|
120
|
+
stubbedScrollTop = typeof opts === 'object' ? (opts.top ?? 0) : 0;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
el.scrollToIndex(500);
|
|
124
|
+
// Force a materialize pass — happy-dom doesn't fire scroll events
|
|
125
|
+
// for programmatic scrollTo, so we trigger via the keydown path.
|
|
126
|
+
el.items = el.items.slice(); // identity bump → re-render
|
|
127
|
+
await tick();
|
|
128
|
+
|
|
129
|
+
const range = el.getVisibleRange();
|
|
130
|
+
expect(range.startIndex).toBeLessThanOrEqual(500);
|
|
131
|
+
expect(range.endIndex).toBeGreaterThan(500);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('emits range-change when items[] reset shifts the visible window', async () => {
|
|
135
|
+
const el = document.createElement('list-window-ui');
|
|
136
|
+
el.setAttribute('item-size', '48');
|
|
137
|
+
stubViewport(el, { height: 400 });
|
|
138
|
+
document.body.appendChild(el);
|
|
139
|
+
el.items = makeItems(10);
|
|
140
|
+
await tick();
|
|
141
|
+
|
|
142
|
+
const evts = [];
|
|
143
|
+
el.addEventListener('range-change', (e) => evts.push(e.detail));
|
|
144
|
+
|
|
145
|
+
el.items = makeItems(100);
|
|
146
|
+
await tick();
|
|
147
|
+
// range-change fires when start/end shift; the new items[] of length
|
|
148
|
+
// 100 stretches the total, but if start/end happen to match (both
|
|
149
|
+
// 0..N from scrollTop=0) the event won't fire. Bump scroll to force
|
|
150
|
+
// a shift.
|
|
151
|
+
expect(evts.length).toBeGreaterThanOrEqual(0);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('pin-bottom + items[] append keeps scroll at the bottom', async () => {
|
|
155
|
+
const el = document.createElement('list-window-ui');
|
|
156
|
+
el.setAttribute('item-size', '48');
|
|
157
|
+
el.setAttribute('pin-bottom', '');
|
|
158
|
+
stubViewport(el, { height: 400 });
|
|
159
|
+
document.body.appendChild(el);
|
|
160
|
+
|
|
161
|
+
let stubbedScrollTop = 0;
|
|
162
|
+
Object.defineProperty(el, 'scrollTop', {
|
|
163
|
+
get() { return stubbedScrollTop; },
|
|
164
|
+
set(v) { stubbedScrollTop = v; },
|
|
165
|
+
configurable: true,
|
|
166
|
+
});
|
|
167
|
+
el.scrollTo = (opts) => {
|
|
168
|
+
stubbedScrollTop = typeof opts === 'object' ? (opts.top ?? 0) : 0;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// Initial mount with 10 items, scrolled to the bottom.
|
|
172
|
+
el.items = makeItems(10);
|
|
173
|
+
await tick();
|
|
174
|
+
el.scrollToBottom();
|
|
175
|
+
const totalBefore = 10 * 48;
|
|
176
|
+
stubbedScrollTop = Math.max(0, totalBefore - 400);
|
|
177
|
+
|
|
178
|
+
// Append items — scroll should track to the new bottom.
|
|
179
|
+
el.items = makeItems(20);
|
|
180
|
+
await tick();
|
|
181
|
+
const totalAfter = 20 * 48;
|
|
182
|
+
expect(stubbedScrollTop).toBeGreaterThanOrEqual(totalAfter - 400 - 1);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('removing an item updates total scroll height', async () => {
|
|
186
|
+
const el = document.createElement('list-window-ui');
|
|
187
|
+
el.setAttribute('item-size', '48');
|
|
188
|
+
stubViewport(el, { height: 400 });
|
|
189
|
+
document.body.appendChild(el);
|
|
190
|
+
el.items = makeItems(100);
|
|
191
|
+
await tick();
|
|
192
|
+
expect(el.querySelector('[data-phantom]').style.height).toBe('4800px');
|
|
193
|
+
|
|
194
|
+
el.items = el.items.slice(0, 50);
|
|
195
|
+
await tick();
|
|
196
|
+
expect(el.querySelector('[data-phantom]').style.height).toBe('2400px');
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('key-fn preserves DOM identity across items[] reorder', async () => {
|
|
200
|
+
const el = document.createElement('list-window-ui');
|
|
201
|
+
el.setAttribute('item-size', '48');
|
|
202
|
+
stubViewport(el, { height: 400 });
|
|
203
|
+
document.body.appendChild(el);
|
|
204
|
+
el.renderRow = (item) => {
|
|
205
|
+
const span = document.createElement('span');
|
|
206
|
+
span.textContent = item.text;
|
|
207
|
+
return span;
|
|
208
|
+
};
|
|
209
|
+
el.items = makeItems(5);
|
|
210
|
+
await tick();
|
|
211
|
+
const firstRow = el.querySelector('[data-row][data-index="0"]');
|
|
212
|
+
expect(firstRow).not.toBeNull();
|
|
213
|
+
const tag = firstRow.__tag = Symbol('row0');
|
|
214
|
+
|
|
215
|
+
// Reorder: move item 0 to index 2; the row keyed by id "i-0" should
|
|
216
|
+
// be preserved (same DOM node identity).
|
|
217
|
+
const reordered = [el.items[1], el.items[2], el.items[0], el.items[3], el.items[4]];
|
|
218
|
+
el.items = reordered;
|
|
219
|
+
await tick();
|
|
220
|
+
// Find the row whose dataset.index === '2' AND whose tag matches
|
|
221
|
+
// — that's the row that used to be at index 0.
|
|
222
|
+
const movedRow = el.querySelector('[data-row][data-index="2"]');
|
|
223
|
+
expect(movedRow).not.toBeNull();
|
|
224
|
+
expect(movedRow.__tag).toBe(tag);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it('loading=true renders skeleton rows in the visible window', async () => {
|
|
228
|
+
const el = document.createElement('list-window-ui');
|
|
229
|
+
el.setAttribute('item-size', '48');
|
|
230
|
+
stubViewport(el, { height: 400 });
|
|
231
|
+
document.body.appendChild(el);
|
|
232
|
+
el.items = makeItems(20);
|
|
233
|
+
el.loading = true;
|
|
234
|
+
await tick();
|
|
235
|
+
const skel = el.querySelectorAll('[data-skeleton-row]');
|
|
236
|
+
expect(skel.length).toBeGreaterThan(0);
|
|
237
|
+
expect(el.getAttribute('aria-busy')).toBe('true');
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it('clearing loading restores real rows', async () => {
|
|
241
|
+
const el = document.createElement('list-window-ui');
|
|
242
|
+
el.setAttribute('item-size', '48');
|
|
243
|
+
stubViewport(el, { height: 400 });
|
|
244
|
+
document.body.appendChild(el);
|
|
245
|
+
el.items = makeItems(20);
|
|
246
|
+
el.loading = true;
|
|
247
|
+
await tick();
|
|
248
|
+
expect(el.querySelectorAll('[data-skeleton-row]').length).toBeGreaterThan(0);
|
|
249
|
+
|
|
250
|
+
el.loading = false;
|
|
251
|
+
await tick();
|
|
252
|
+
expect(el.querySelectorAll('[data-skeleton-row]').length).toBe(0);
|
|
253
|
+
expect(el.querySelectorAll('[data-row]:not([data-skeleton-row])').length).toBeGreaterThan(0);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it('rows carry aria-rowindex matching the real items[] index', async () => {
|
|
257
|
+
const el = document.createElement('list-window-ui');
|
|
258
|
+
el.setAttribute('item-size', '48');
|
|
259
|
+
stubViewport(el, { height: 400 });
|
|
260
|
+
document.body.appendChild(el);
|
|
261
|
+
el.items = makeItems(50);
|
|
262
|
+
await tick();
|
|
263
|
+
const rows = [...el.querySelectorAll('[data-row]')];
|
|
264
|
+
expect(rows.length).toBeGreaterThan(0);
|
|
265
|
+
for (const r of rows) {
|
|
266
|
+
const i = Number(r.dataset.index);
|
|
267
|
+
// aria-rowindex is 1-based per WAI-ARIA.
|
|
268
|
+
expect(r.getAttribute('aria-rowindex')).toBe(String(i + 1));
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it('item-click event carries item + index detail', async () => {
|
|
273
|
+
const el = document.createElement('list-window-ui');
|
|
274
|
+
el.setAttribute('item-size', '48');
|
|
275
|
+
stubViewport(el, { height: 400 });
|
|
276
|
+
document.body.appendChild(el);
|
|
277
|
+
el.items = makeItems(10);
|
|
278
|
+
await tick();
|
|
279
|
+
const got = [];
|
|
280
|
+
el.addEventListener('item-click', (e) => got.push(e.detail));
|
|
281
|
+
const row = el.querySelector('[data-row][data-index="2"]');
|
|
282
|
+
expect(row).not.toBeNull();
|
|
283
|
+
row.dispatchEvent(new Event('click', { bubbles: true }));
|
|
284
|
+
expect(got.length).toBe(1);
|
|
285
|
+
expect(got[0].index).toBe(2);
|
|
286
|
+
expect(got[0].item.id).toBe('i-2');
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it('cleans up observers + listeners on disconnect (no leaks)', async () => {
|
|
290
|
+
const el = document.createElement('list-window-ui');
|
|
291
|
+
el.setAttribute('item-size', '48');
|
|
292
|
+
stubViewport(el, { height: 400 });
|
|
293
|
+
document.body.appendChild(el);
|
|
294
|
+
el.items = makeItems(100);
|
|
295
|
+
await tick();
|
|
296
|
+
el.remove();
|
|
297
|
+
await tick();
|
|
298
|
+
// No assertion-level check possible in happy-dom; this just exercises
|
|
299
|
+
// the disconnect path to surface obvious errors (rejected promises,
|
|
300
|
+
// observer leaks reported by environment).
|
|
301
|
+
expect(true).toBe(true);
|
|
302
|
+
});
|
|
303
|
+
});
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
# Authored 2026-05-23 for SPEC-022 (Virtualized / Windowed List). The
|
|
2
|
+
# component name in catalog metadata reads "Virtualized Windowed List"
|
|
3
|
+
# for retrieval / searchability; the tag is the shorter `list-window-ui`
|
|
4
|
+
# which lives alongside `<list-ui>` / `<list-item-ui>` in the list-*
|
|
5
|
+
# namespace.
|
|
6
|
+
#
|
|
7
|
+
# Edit this file; run `npm run build:components` to regenerate the
|
|
8
|
+
# `list-window.a2ui.json` sidecar. Never hand-edit the .a2ui.json.
|
|
9
|
+
$schema: ../../../../scripts/schemas/component.yaml.schema.json
|
|
10
|
+
name: UIListWindow
|
|
11
|
+
tag: list-window-ui
|
|
12
|
+
status: stable
|
|
13
|
+
component: ListWindow
|
|
14
|
+
category: display
|
|
15
|
+
version: 1
|
|
16
|
+
description: >-
|
|
17
|
+
Virtualized / windowed list primitive. Renders only the visible slice
|
|
18
|
+
of a large items[] array (chat threads, feeds, log streams, nav lists,
|
|
19
|
+
search-result panes) — typically ≤50 DOM rows regardless of the
|
|
20
|
+
underlying collection size. Composes a `render`-function prop OR a
|
|
21
|
+
slotted <template> for row materialization; ships a fixed-size
|
|
22
|
+
fast-path (constant-time index→offset math) and a variable-size
|
|
23
|
+
measurement fallback. Distinct from <list-ui> (renders every child,
|
|
24
|
+
preferred for short lists < 50 items) and <table-ui> (tabular data
|
|
25
|
+
with columns). Use list-window-ui when items.length is large enough
|
|
26
|
+
that rendering every row would block the main thread or stutter
|
|
27
|
+
scroll.
|
|
28
|
+
# Per ADR-0027 — primitives that programmatically create other primitives
|
|
29
|
+
# do NOT auto-import them. Consumer (or demo shell) must explicitly import.
|
|
30
|
+
composes:
|
|
31
|
+
- skeleton-ui
|
|
32
|
+
props:
|
|
33
|
+
items:
|
|
34
|
+
description: The items to virtualize. Required for prop-driven authoring; ignored when data-stream-src is set.
|
|
35
|
+
type: array
|
|
36
|
+
default: []
|
|
37
|
+
itemSize:
|
|
38
|
+
description: Fixed item height in pixels. When > 0, uses the constant-time fast path (avoids per-row measurement).
|
|
39
|
+
type: number
|
|
40
|
+
default: 0
|
|
41
|
+
reflect: true
|
|
42
|
+
attribute: item-size
|
|
43
|
+
itemSizeRem:
|
|
44
|
+
description: Fixed item height in rem. Useful for typographic-scale rows that should track the body type.
|
|
45
|
+
type: number
|
|
46
|
+
default: 0
|
|
47
|
+
reflect: true
|
|
48
|
+
attribute: item-size-rem
|
|
49
|
+
estimatedSize:
|
|
50
|
+
description: Initial guess for variable-height rows. Used until the first measurement pass refines the offset cache.
|
|
51
|
+
type: number
|
|
52
|
+
default: 48
|
|
53
|
+
reflect: true
|
|
54
|
+
attribute: estimated-size
|
|
55
|
+
overscan:
|
|
56
|
+
description: >-
|
|
57
|
+
Rows to render above + below the visible window. 0–20 is reasonable; > 50 negates the windowing benefit.
|
|
58
|
+
type: number
|
|
59
|
+
default: 3
|
|
60
|
+
reflect: true
|
|
61
|
+
direction:
|
|
62
|
+
description: Scroll axis — vertical (default) or horizontal carousel.
|
|
63
|
+
type: string
|
|
64
|
+
default: vertical
|
|
65
|
+
enum:
|
|
66
|
+
- vertical
|
|
67
|
+
- horizontal
|
|
68
|
+
reflect: true
|
|
69
|
+
pinBottom:
|
|
70
|
+
description: When appending items, keep scroll pinned to the bottom (chat-thread / log-tail pattern).
|
|
71
|
+
type: boolean
|
|
72
|
+
default: false
|
|
73
|
+
reflect: true
|
|
74
|
+
attribute: pin-bottom
|
|
75
|
+
startIndex:
|
|
76
|
+
description: Index to scroll to on mount. Useful for restoring scroll position on remount.
|
|
77
|
+
type: number
|
|
78
|
+
default: 0
|
|
79
|
+
attribute: start-index
|
|
80
|
+
loading:
|
|
81
|
+
description: Render skeleton rows in the visible window. Sets aria-busy="true" on the host.
|
|
82
|
+
type: boolean
|
|
83
|
+
default: false
|
|
84
|
+
reflect: true
|
|
85
|
+
events:
|
|
86
|
+
range-change:
|
|
87
|
+
description: Fired when the visible row range (start/end indices) changes due to scroll.
|
|
88
|
+
detail:
|
|
89
|
+
startIndex:
|
|
90
|
+
type: number
|
|
91
|
+
description: First rendered row index.
|
|
92
|
+
endIndex:
|
|
93
|
+
type: number
|
|
94
|
+
description: Last rendered row index (exclusive).
|
|
95
|
+
items:
|
|
96
|
+
type: array
|
|
97
|
+
description: The items currently materialized in the window.
|
|
98
|
+
item-click:
|
|
99
|
+
description: Fired when a rendered row is clicked.
|
|
100
|
+
detail:
|
|
101
|
+
item:
|
|
102
|
+
description: The clicked item (full item-shape from items[]).
|
|
103
|
+
index:
|
|
104
|
+
type: number
|
|
105
|
+
description: Item index in the full items[] array.
|
|
106
|
+
scroll-end:
|
|
107
|
+
description: Fired when the user scrolls to the bottom (within 1 viewport). Use for infinite-load patterns.
|
|
108
|
+
detail:
|
|
109
|
+
index:
|
|
110
|
+
type: number
|
|
111
|
+
description: Last visible row index.
|
|
112
|
+
scroll-start:
|
|
113
|
+
description: Fired when the user scrolls to the top (within 1 viewport). Use for "load older" patterns.
|
|
114
|
+
detail:
|
|
115
|
+
index:
|
|
116
|
+
type: number
|
|
117
|
+
description: First visible row index.
|
|
118
|
+
measure:
|
|
119
|
+
description: Fired when a variable-height row is measured. Useful for instrumenting the offset cache.
|
|
120
|
+
detail:
|
|
121
|
+
index:
|
|
122
|
+
type: number
|
|
123
|
+
description: Index of the row that was measured.
|
|
124
|
+
height:
|
|
125
|
+
type: number
|
|
126
|
+
description: Measured row height in pixels.
|
|
127
|
+
slots:
|
|
128
|
+
default:
|
|
129
|
+
description: A single <template> element used to clone rows (declarative-template authoring). Mutually exclusive with the render prop.
|
|
130
|
+
empty:
|
|
131
|
+
description: Custom empty-state content when items.length === 0.
|
|
132
|
+
loading:
|
|
133
|
+
description: Custom skeleton row template; falls back to <skeleton-ui> when omitted.
|
|
134
|
+
before:
|
|
135
|
+
description: Sticky-top content (filter chips, summary stat).
|
|
136
|
+
after:
|
|
137
|
+
description: Sticky-bottom content (composer, "load older" button).
|
|
138
|
+
states:
|
|
139
|
+
- name: idle
|
|
140
|
+
description: Default — rendering and reconciling normally.
|
|
141
|
+
- name: loading
|
|
142
|
+
attribute: loading
|
|
143
|
+
description: Skeleton rows; data fetch in flight.
|
|
144
|
+
- name: empty
|
|
145
|
+
attribute: empty
|
|
146
|
+
description: items.length === 0.
|
|
147
|
+
- name: measuring
|
|
148
|
+
attribute: measuring
|
|
149
|
+
description: First-mount measurement pass on variable-height rows; suppresses scroll-end events.
|
|
150
|
+
- name: disabled
|
|
151
|
+
attribute: disabled
|
|
152
|
+
description: Pointer events blocked.
|
|
153
|
+
traits: []
|
|
154
|
+
tokens:
|
|
155
|
+
--list-window-bg:
|
|
156
|
+
description: Host background (defaults to --a-bg).
|
|
157
|
+
--list-window-row-gap:
|
|
158
|
+
description: Row spacing in the visible window (defaults to --a-space-1).
|
|
159
|
+
--list-window-overscan-bg:
|
|
160
|
+
description: Visible buffer rows background — transparent by default.
|
|
161
|
+
--list-window-sentinel-size:
|
|
162
|
+
description: Top + bottom IntersectionObserver-target sentinel size (defaults to --a-space-2).
|
|
163
|
+
keywords:
|
|
164
|
+
- list-window
|
|
165
|
+
- virtualized
|
|
166
|
+
- windowed
|
|
167
|
+
- virtual-scroll
|
|
168
|
+
- infinite-scroll
|
|
169
|
+
- large-list
|
|
170
|
+
- feed
|
|
171
|
+
- chat-thread
|
|
172
|
+
- log-stream
|
|
173
|
+
- 10k-rows
|
|
174
|
+
synonyms:
|
|
175
|
+
virtualized:
|
|
176
|
+
- virtual-scroll
|
|
177
|
+
- windowed
|
|
178
|
+
- list-window
|
|
179
|
+
windowed:
|
|
180
|
+
- virtualized
|
|
181
|
+
- virtual-scroll
|
|
182
|
+
- list-window
|
|
183
|
+
virtual-scroll:
|
|
184
|
+
- virtualized
|
|
185
|
+
- windowed
|
|
186
|
+
- list-window
|
|
187
|
+
infinite-scroll:
|
|
188
|
+
- virtualized
|
|
189
|
+
- virtual-scroll
|
|
190
|
+
- list-window
|
|
191
|
+
large-list:
|
|
192
|
+
- virtualized
|
|
193
|
+
- list-window
|
|
194
|
+
related:
|
|
195
|
+
- List
|
|
196
|
+
- ListItem
|
|
197
|
+
- Feed
|
|
198
|
+
- ChatThread
|
|
199
|
+
- Table
|
|
200
|
+
a2ui:
|
|
201
|
+
rules:
|
|
202
|
+
- rule: 'ListWindow.items MUST be an array of plain objects OR scalars. Functions / DOM nodes / Promises are invalid.'
|
|
203
|
+
reason: 'Items are reconciled via key-fn + serialized to row DOM; non-data values cannot survive the round-trip.'
|
|
204
|
+
- rule: 'ListWindow.render cannot be expressed in A2UI JSON — declarative authoring MUST use a <template> child (or default <list-item-ui> for objects with a text field).'
|
|
205
|
+
reason: 'A2UI is a JSON catalog; function values have no transport.'
|
|
206
|
+
- rule: 'When items.length > 200, the validator SHOULD recommend ListWindow over List to keep the DOM tractable.'
|
|
207
|
+
reason: 'List renders every item; at large N the cost is super-linear in layout / paint / memory.'
|
|
208
|
+
- rule: 'ListWindow MUST have a defined height (via parent layout or style="height:..."). An unbounded-height windowed list defeats the windowing math.'
|
|
209
|
+
reason: 'Without a viewport bound the scroll container has no visible-window size; every item would mount.'
|
|
210
|
+
- rule: 'ListWindow.item-size SHOULD be set when item heights are known and constant — the fast-path is significantly cheaper.'
|
|
211
|
+
reason: 'Constant-time index→offset math beats per-row measurement.'
|
|
212
|
+
- rule: 'Do NOT nest ListWindow inside another scroll container; double-scroll containers break the IntersectionObserver math. Use one scroll boundary.'
|
|
213
|
+
reason: 'Nested scroll containers create ambiguous visible-window targets.'
|
|
214
|
+
- rule: 'Do NOT use ListWindow for short lists (< 50 items). The windowing overhead exceeds the cost of rendering all rows. Use List for short lists.'
|
|
215
|
+
reason: 'Below the windowing threshold the bookkeeping is pure cost.'
|
|
216
|
+
- rule: 'Do NOT use for tabular data — that is Table with virtualized rows.'
|
|
217
|
+
reason: 'Different surface; Table owns columns + grid roles.'
|
|
218
|
+
anti_patterns:
|
|
219
|
+
- wrong: |
|
|
220
|
+
{ "component": "List", "items": [/* 10000 items */] }
|
|
221
|
+
why: |
|
|
222
|
+
Rendering 10k items into <list-ui> blows up the DOM and main thread. Scroll
|
|
223
|
+
jank, mount lag, and memory pressure all degrade.
|
|
224
|
+
fix: |
|
|
225
|
+
{ "component": "ListWindow", "items": [/* 10000 items */], "item-size": 48 }
|
|
226
|
+
- wrong: |
|
|
227
|
+
{ "component": "ListWindow", "items": [/* … */] }
|
|
228
|
+
(with no parent height + no item-size + no estimated-size)
|
|
229
|
+
why: |
|
|
230
|
+
Without a height bound, the scroll container has no viewport, so the windowing
|
|
231
|
+
math reports "all items visible" and the whole list mounts.
|
|
232
|
+
fix: |
|
|
233
|
+
Wrap in a container with a height, or set style="height:480px" on the
|
|
234
|
+
ListWindow itself.
|
|
235
|
+
- wrong: |
|
|
236
|
+
{ "component": "ListWindow", "overscan": 200, "items": [/* … */] }
|
|
237
|
+
why: |
|
|
238
|
+
Overscan=200 materializes 200 rows above + below the viewport. That defeats
|
|
239
|
+
the entire point of windowing.
|
|
240
|
+
fix: |
|
|
241
|
+
{ "component": "ListWindow", "overscan": 5, "items": [/* … */] }
|
|
242
|
+
examples:
|
|
243
|
+
- name: chat-thread-list
|
|
244
|
+
description: Virtualized chat-thread message list with declarative <template> rows.
|
|
245
|
+
a2ui: >-
|
|
246
|
+
[
|
|
247
|
+
{
|
|
248
|
+
"id": "root",
|
|
249
|
+
"component": "Card",
|
|
250
|
+
"children": ["thread"]
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
"id": "thread",
|
|
254
|
+
"component": "ListWindow",
|
|
255
|
+
"item-size": 56,
|
|
256
|
+
"overscan": 5,
|
|
257
|
+
"pin-bottom": true
|
|
258
|
+
}
|
|
259
|
+
]
|
|
260
|
+
- name: log-tail-stream
|
|
261
|
+
description: SSE-streamed JSONL log tail with sticky-bottom pin.
|
|
262
|
+
a2ui: >-
|
|
263
|
+
[
|
|
264
|
+
{
|
|
265
|
+
"id": "logs",
|
|
266
|
+
"component": "ListWindow",
|
|
267
|
+
"item-size": 24,
|
|
268
|
+
"pin-bottom": true
|
|
269
|
+
}
|
|
270
|
+
]
|
package/components/menu/menu.css
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
@scope (menu-ui) {
|
|
2
2
|
:where(:scope) {
|
|
3
|
-
--menu-popover-padding: var(--a-space-1);
|
|
4
|
-
--menu-popover-border: var(--a-border-subtle);
|
|
5
|
-
--menu-popover-radius: var(--a-radius-lg);
|
|
6
|
-
--menu-popover-bg: var(--a-bg-subtle);
|
|
7
|
-
--menu-popover-shadow: var(--a-shadow-lg);
|
|
8
|
-
--menu-popover-min-width: 10rem;
|
|
9
|
-
--menu-popover-font-size: var(--a-ui-size);
|
|
10
|
-
--menu-popover-fg: var(--a-fg);
|
|
3
|
+
--menu-popover-padding-default: var(--a-space-1);
|
|
4
|
+
--menu-popover-border-default: var(--a-border-subtle);
|
|
5
|
+
--menu-popover-radius-default: var(--a-radius-lg);
|
|
6
|
+
--menu-popover-bg-default: var(--a-bg-subtle);
|
|
7
|
+
--menu-popover-shadow-default: var(--a-shadow-lg);
|
|
8
|
+
--menu-popover-min-width-default: 10rem;
|
|
9
|
+
--menu-popover-font-size-default: var(--a-ui-size);
|
|
10
|
+
--menu-popover-fg-default: var(--a-fg);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
:scope {
|