@adia-ai/web-components 0.0.27 → 0.0.29
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/README.md +4 -8
- package/a2ui/index.js +1 -1
- package/components/agent-questions/agent-questions.css +20 -1
- package/components/agent-trace/agent-trace.css +17 -12
- package/components/badge/badge.js +9 -1
- package/components/breadcrumb/breadcrumb.a2ui.json +16 -1
- package/components/breadcrumb/breadcrumb.css +27 -0
- package/components/breadcrumb/breadcrumb.js +95 -17
- package/components/breadcrumb/breadcrumb.yaml +15 -1
- package/components/canvas/canvas.js +1 -1
- package/components/chart/chart.css +20 -13
- package/components/chart/chart.js +49 -17
- package/components/chart-legend/chart-legend.css +30 -54
- package/components/chart-legend/chart-legend.js +48 -30
- package/components/command/command.js +52 -1
- package/components/feed/feed-item.yaml +50 -0
- package/components/feed/feed.a2ui.json +59 -0
- package/components/feed/feed.css +150 -0
- package/components/feed/feed.js +385 -0
- package/components/feed/feed.yaml +33 -0
- package/components/index.js +2 -0
- package/components/swatch/swatch.a2ui.json +116 -0
- package/components/swatch/swatch.css +141 -0
- package/components/swatch/swatch.js +121 -0
- package/components/swatch/swatch.yaml +101 -0
- package/components/timeline/timeline.css +5 -1
- package/components/toast/toast.js +48 -178
- package/components/tooltip/tooltip.css +3 -3
- package/core/provider.js +1 -0
- package/index.css +3 -2
- package/index.js +15 -7
- package/package.json +1 -5
- package/styles/components.css +1 -0
- package/patterns/a2ui-root/a2ui-root.a2ui.json +0 -125
- package/patterns/a2ui-root/a2ui-root.js +0 -191
- package/patterns/a2ui-root/a2ui-root.yaml +0 -87
- package/patterns/adia-chat/adia-chat.a2ui.json +0 -149
- package/patterns/adia-chat/adia-chat.css +0 -10
- package/patterns/adia-chat/adia-chat.js +0 -297
- package/patterns/adia-chat/adia-chat.yaml +0 -118
- package/patterns/adia-chat/css/adia-chat.empty.css +0 -12
- package/patterns/adia-chat/css/adia-chat.layout.css +0 -60
- package/patterns/adia-chat/css/adia-chat.markdown.css +0 -74
- package/patterns/adia-chat/css/adia-chat.messages.css +0 -87
- package/patterns/adia-chat/css/adia-chat.streaming.css +0 -30
- package/patterns/adia-chat/css/adia-chat.tokens.css +0 -95
- package/patterns/adia-editor/adia-editor.a2ui.json +0 -73
- package/patterns/adia-editor/adia-editor.css +0 -6
- package/patterns/adia-editor/adia-editor.js +0 -56
- package/patterns/adia-editor/adia-editor.yaml +0 -59
- package/patterns/adia-editor/css/adia-editor.layout.css +0 -171
- package/patterns/adia-editor/css/adia-editor.tokens.css +0 -28
- package/patterns/app-nav/app-nav.a2ui.json +0 -89
- package/patterns/app-nav/app-nav.css +0 -92
- package/patterns/app-nav/app-nav.js +0 -112
- package/patterns/app-nav/app-nav.yaml +0 -54
- package/patterns/app-nav-group/app-nav-group.a2ui.json +0 -82
- package/patterns/app-nav-group/app-nav-group.css +0 -264
- package/patterns/app-nav-group/app-nav-group.js +0 -116
- package/patterns/app-nav-group/app-nav-group.yaml +0 -59
- package/patterns/app-nav-item/app-nav-item.a2ui.json +0 -83
- package/patterns/app-nav-item/app-nav-item.css +0 -162
- package/patterns/app-nav-item/app-nav-item.js +0 -42
- package/patterns/app-nav-item/app-nav-item.yaml +0 -62
- package/patterns/app-shell/app-shell.a2ui.json +0 -129
- package/patterns/app-shell/app-shell.css +0 -14
- package/patterns/app-shell/app-shell.js +0 -251
- package/patterns/app-shell/app-shell.yaml +0 -89
- package/patterns/app-shell/css/app-shell.collapsed.css +0 -86
- package/patterns/app-shell/css/app-shell.helpers.css +0 -42
- package/patterns/app-shell/css/app-shell.main.css +0 -172
- package/patterns/app-shell/css/app-shell.shell.css +0 -44
- package/patterns/app-shell/css/app-shell.sidebar.css +0 -161
- package/patterns/app-shell/css/app-shell.templates.css +0 -214
- package/patterns/app-shell/css/app-shell.tokens.css +0 -119
- package/patterns/gen-ui/gen-ui.a2ui.json +0 -72
- package/patterns/gen-ui/gen-ui.css +0 -83
- package/patterns/gen-ui/gen-ui.js +0 -136
- package/patterns/gen-ui/gen-ui.yaml +0 -43
- package/patterns/index.js +0 -11
- package/patterns/section-nav/section-nav.a2ui.json +0 -91
- package/patterns/section-nav/section-nav.css +0 -60
- package/patterns/section-nav/section-nav.js +0 -42
- package/patterns/section-nav/section-nav.yaml +0 -58
- package/patterns/section-nav-group/section-nav-group.a2ui.json +0 -95
- package/patterns/section-nav-group/section-nav-group.css +0 -74
- package/patterns/section-nav-group/section-nav-group.js +0 -84
- package/patterns/section-nav-group/section-nav-group.yaml +0 -66
- package/patterns/section-nav-item/section-nav-item.a2ui.json +0 -97
- package/patterns/section-nav-item/section-nav-item.css +0 -106
- package/patterns/section-nav-item/section-nav-item.js +0 -66
- package/patterns/section-nav-item/section-nav-item.yaml +0 -70
- package/styles/layouts/admin.css +0 -7
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <feed-ui> + <feed-item-ui> — Shared top-layer feed channel.
|
|
3
|
+
*
|
|
4
|
+
* Per docs/specs/feed-channel.md (SPEC-FEED-CHANNEL-001).
|
|
5
|
+
*
|
|
6
|
+
* Phase 1 (skeleton) ships here:
|
|
7
|
+
* - Per-position singletons (`<feed-ui position="bottom-right">`)
|
|
8
|
+
* resolving OD-FEED-1; mounted lazily into document.body via
|
|
9
|
+
* Popover API for top-layer placement.
|
|
10
|
+
* - Auto-fade `<feed-item-ui>` policy. Sticky-dismissible and
|
|
11
|
+
* action-required policies are stubs that respect the contract
|
|
12
|
+
* (no auto-dismiss when `duration` is null/0; close button
|
|
13
|
+
* surfaces when `dismissible` is set) but the action-required
|
|
14
|
+
* focus-trap is deferred.
|
|
15
|
+
* - Static API: AdiaFeed.post() / .get() / .clear() / .purge()
|
|
16
|
+
* — `purge()` directly addresses the audit's L-B4 container-leak
|
|
17
|
+
* finding by giving consumers a tear-down hook.
|
|
18
|
+
* - Global event channel: window.dispatchEvent(new CustomEvent(
|
|
19
|
+
* 'feed', { detail: { text, position, ... } })) — same shape as
|
|
20
|
+
* AdiaFeed.post() so any code can post without importing the
|
|
21
|
+
* module directly. Idempotent listener install (HMR-safe).
|
|
22
|
+
*
|
|
23
|
+
* Toast migration (spec § 2.5) is deferred — toast-ui keeps its own
|
|
24
|
+
* container + API for now; the migration happens once the feed-ui
|
|
25
|
+
* surface has soaked.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { AdiaElement, html } from '../../core/element.js';
|
|
29
|
+
|
|
30
|
+
/* ── Container — one per position, mounted into document.body ── */
|
|
31
|
+
|
|
32
|
+
class AdiaFeedContainer extends AdiaElement {
|
|
33
|
+
static properties = {
|
|
34
|
+
position: { type: String, default: 'bottom-right', reflect: true },
|
|
35
|
+
max: { type: Number, default: 5, reflect: true },
|
|
36
|
+
};
|
|
37
|
+
static template = () => html``;
|
|
38
|
+
|
|
39
|
+
connected() {
|
|
40
|
+
if (!this.hasAttribute('role')) this.setAttribute('role', 'region');
|
|
41
|
+
if (!this.hasAttribute('aria-label')) this.setAttribute('aria-label', 'Feed');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
customElements.define('feed-ui', AdiaFeedContainer);
|
|
46
|
+
|
|
47
|
+
/* ── Item — one per posted message ── */
|
|
48
|
+
|
|
49
|
+
class AdiaFeedItem extends AdiaElement {
|
|
50
|
+
#timer = null;
|
|
51
|
+
#removing = false;
|
|
52
|
+
#closeTimer = null;
|
|
53
|
+
#openRaf = null;
|
|
54
|
+
|
|
55
|
+
static properties = {
|
|
56
|
+
text: { type: String, default: '', reflect: true },
|
|
57
|
+
heading: { type: String, default: '', reflect: true },
|
|
58
|
+
icon: { type: String, default: '', reflect: true },
|
|
59
|
+
variant: { type: String, default: 'default', reflect: true },
|
|
60
|
+
duration: { type: Number, default: 4000, reflect: true },
|
|
61
|
+
dismissible: { type: Boolean, default: false, reflect: true },
|
|
62
|
+
// Phase 2: action-required policy. When set, the item carries an
|
|
63
|
+
// action button that the user MUST click (or dismiss) before the
|
|
64
|
+
// item goes away. Spec §2.3 — action-required role=alertdialog,
|
|
65
|
+
// focus is trapped until choice is made.
|
|
66
|
+
action: { type: String, default: '', reflect: true },
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
static parts = {
|
|
70
|
+
body: '<div slot="body"></div>',
|
|
71
|
+
};
|
|
72
|
+
static template = () => html``;
|
|
73
|
+
|
|
74
|
+
#onPress = (e) => {
|
|
75
|
+
if (e.target.closest('[data-feed-close]')) { this.dismiss(); return; }
|
|
76
|
+
// Phase 2: action button — fires the action callback (if registered
|
|
77
|
+
// via FeedHandle.update with onAction) then dismisses. The handle's
|
|
78
|
+
// .update({onAction: fn}) populates this.#onAction below.
|
|
79
|
+
if (e.target.closest('[data-feed-action]')) {
|
|
80
|
+
try { this.#onAction?.(); } catch (err) { console.warn('[feed-item] action handler threw:', err); }
|
|
81
|
+
this.dismiss();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// Phase 2 focus-trap state — only used when the policy is action-required.
|
|
86
|
+
#onAction = null;
|
|
87
|
+
#focusTrapPrev = null;
|
|
88
|
+
#onTrapKeydown = null;
|
|
89
|
+
|
|
90
|
+
connected() {
|
|
91
|
+
this.addEventListener('press', this.#onPress);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
#getDuration() {
|
|
95
|
+
const raw = getComputedStyle(this).getPropertyValue('--feed-item-duration').trim();
|
|
96
|
+
return parseFloat(raw) || 200;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
render() {
|
|
100
|
+
const body = this.ensure('body');
|
|
101
|
+
body.textContent = '';
|
|
102
|
+
if (this.heading) {
|
|
103
|
+
const h = document.createElement('strong');
|
|
104
|
+
h.textContent = this.heading;
|
|
105
|
+
h.style.display = 'block';
|
|
106
|
+
body.appendChild(h);
|
|
107
|
+
}
|
|
108
|
+
if (this.text) {
|
|
109
|
+
const t = document.createElement('span');
|
|
110
|
+
t.textContent = this.text;
|
|
111
|
+
body.appendChild(t);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/* Inferred policy roles per spec §2.4. Auto-fade gets `status`;
|
|
115
|
+
sticky danger/warning gets `alert`; action-required (sticky +
|
|
116
|
+
has [action]) gets `alertdialog` and a focus trap. */
|
|
117
|
+
const isSticky = !this.duration || this.duration <= 0;
|
|
118
|
+
const isLoud = this.variant === 'danger' || this.variant === 'warning';
|
|
119
|
+
const isActionRequired = isSticky && !!this.action;
|
|
120
|
+
let role = 'status';
|
|
121
|
+
if (isActionRequired) role = 'alertdialog';
|
|
122
|
+
else if (isSticky && isLoud) role = 'alert';
|
|
123
|
+
this.setAttribute('role', role);
|
|
124
|
+
this.setAttribute('aria-live', role === 'alert' || role === 'alertdialog' ? 'assertive' : 'polite');
|
|
125
|
+
if (isActionRequired) this.setAttribute('aria-modal', 'false'); // not page-blocking; focus-trap only
|
|
126
|
+
|
|
127
|
+
/* Render dismiss button for sticky items (spec §2.2 — default true
|
|
128
|
+
for sticky, false for auto-fade). Action-required items still
|
|
129
|
+
allow Escape to dismiss for safety; the action button is not the
|
|
130
|
+
only escape. */
|
|
131
|
+
const wantsClose = this.dismissible || isSticky;
|
|
132
|
+
let close = this.querySelector(':scope > [data-feed-close]');
|
|
133
|
+
if (wantsClose && !close) {
|
|
134
|
+
close = document.createElement('button-ui');
|
|
135
|
+
close.setAttribute('data-feed-close', '');
|
|
136
|
+
close.setAttribute('icon', 'x');
|
|
137
|
+
close.setAttribute('variant', 'ghost');
|
|
138
|
+
close.setAttribute('size', 'sm');
|
|
139
|
+
close.setAttribute('aria-label', 'Dismiss');
|
|
140
|
+
this.appendChild(close);
|
|
141
|
+
} else if (!wantsClose && close) {
|
|
142
|
+
close.remove();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/* Phase 2 — render the action button when [action] is set. Sits
|
|
146
|
+
between the body and the close button. */
|
|
147
|
+
let actionBtn = this.querySelector(':scope > [data-feed-action]');
|
|
148
|
+
if (this.action) {
|
|
149
|
+
if (!actionBtn) {
|
|
150
|
+
actionBtn = document.createElement('button-ui');
|
|
151
|
+
actionBtn.setAttribute('data-feed-action', '');
|
|
152
|
+
actionBtn.setAttribute('variant', 'ghost');
|
|
153
|
+
actionBtn.setAttribute('size', 'sm');
|
|
154
|
+
if (close && close.parentElement === this) this.insertBefore(actionBtn, close);
|
|
155
|
+
else this.appendChild(actionBtn);
|
|
156
|
+
}
|
|
157
|
+
actionBtn.setAttribute('text', this.action);
|
|
158
|
+
} else if (actionBtn) {
|
|
159
|
+
actionBtn.remove();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/* Focus-trap activation for action-required. */
|
|
163
|
+
if (isActionRequired) this.#installFocusTrap();
|
|
164
|
+
else this.#uninstallFocusTrap();
|
|
165
|
+
|
|
166
|
+
if (!this.hasAttribute('data-open') && !this.#removing) {
|
|
167
|
+
this.#openRaf = requestAnimationFrame(() => {
|
|
168
|
+
this.#openRaf = null;
|
|
169
|
+
this.setAttribute('data-open', '');
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
this.#scheduleAutoDismiss();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
#scheduleAutoDismiss() {
|
|
176
|
+
if (this.#timer) clearTimeout(this.#timer);
|
|
177
|
+
if (this.duration && this.duration > 0) {
|
|
178
|
+
this.#timer = setTimeout(() => this.dismiss(), this.duration);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
dismiss() {
|
|
183
|
+
if (this.#removing) return;
|
|
184
|
+
this.#removing = true;
|
|
185
|
+
if (this.#timer) { clearTimeout(this.#timer); this.#timer = null; }
|
|
186
|
+
this.removeAttribute('data-open');
|
|
187
|
+
this.setAttribute('data-closing', '');
|
|
188
|
+
this.#closeTimer = setTimeout(() => {
|
|
189
|
+
this.#closeTimer = null;
|
|
190
|
+
const container = this.parentElement;
|
|
191
|
+
this.dispatchEvent(new Event('close', { bubbles: true }));
|
|
192
|
+
this.remove();
|
|
193
|
+
if (container?.matches?.('feed-ui')) AdiaFeed.releaseContainerIfEmpty(container);
|
|
194
|
+
}, this.#getDuration());
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
update(patch) {
|
|
198
|
+
if (!patch || typeof patch !== 'object') return;
|
|
199
|
+
for (const k of Object.keys(patch)) {
|
|
200
|
+
if (k in AdiaFeedItem.properties) this[k] = patch[k];
|
|
201
|
+
}
|
|
202
|
+
// Phase 2: handle is set via the FeedHandle's update(); not a
|
|
203
|
+
// reflected attribute, so it lives outside the property loop.
|
|
204
|
+
if (typeof patch.onAction === 'function') this.#onAction = patch.onAction;
|
|
205
|
+
this.#scheduleAutoDismiss();
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Phase 2 focus-trap. Installs on action-required items; saves the
|
|
209
|
+
// previously-focused element so we can return focus on dismiss; cycles
|
|
210
|
+
// Tab/Shift-Tab between focusable descendants; Escape dismisses.
|
|
211
|
+
#installFocusTrap() {
|
|
212
|
+
if (this.#onTrapKeydown) return; // already installed
|
|
213
|
+
this.#focusTrapPrev = document.activeElement;
|
|
214
|
+
const focusables = () => [...this.querySelectorAll('button, button-ui, [tabindex]:not([tabindex="-1"]), input, [data-feed-action], [data-feed-close]')]
|
|
215
|
+
.filter((el) => !el.hasAttribute('disabled') && el.offsetParent !== null);
|
|
216
|
+
this.#onTrapKeydown = (e) => {
|
|
217
|
+
if (e.key === 'Escape') { e.stopPropagation(); this.dismiss(); return; }
|
|
218
|
+
if (e.key !== 'Tab') return;
|
|
219
|
+
const els = focusables();
|
|
220
|
+
if (!els.length) return;
|
|
221
|
+
const first = els[0];
|
|
222
|
+
const last = els[els.length - 1];
|
|
223
|
+
const active = document.activeElement;
|
|
224
|
+
if (e.shiftKey && active === first) { e.preventDefault(); last.focus(); }
|
|
225
|
+
else if (!e.shiftKey && active === last) { e.preventDefault(); first.focus(); }
|
|
226
|
+
};
|
|
227
|
+
this.addEventListener('keydown', this.#onTrapKeydown, true);
|
|
228
|
+
// Move focus into the item — prefer the action button.
|
|
229
|
+
queueMicrotask(() => {
|
|
230
|
+
const els = focusables();
|
|
231
|
+
const action = this.querySelector('[data-feed-action]');
|
|
232
|
+
(action || els[0])?.focus?.();
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
#uninstallFocusTrap() {
|
|
237
|
+
if (!this.#onTrapKeydown) return;
|
|
238
|
+
this.removeEventListener('keydown', this.#onTrapKeydown, true);
|
|
239
|
+
this.#onTrapKeydown = null;
|
|
240
|
+
// Restore focus to whatever had it before the trap engaged.
|
|
241
|
+
try { this.#focusTrapPrev?.focus?.(); } catch { /* element may have been removed */ }
|
|
242
|
+
this.#focusTrapPrev = null;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
disconnected() {
|
|
246
|
+
this.removeEventListener('press', this.#onPress);
|
|
247
|
+
if (this.#timer) { clearTimeout(this.#timer); this.#timer = null; }
|
|
248
|
+
if (this.#closeTimer) { clearTimeout(this.#closeTimer); this.#closeTimer = null; }
|
|
249
|
+
if (this.#openRaf != null) { cancelAnimationFrame(this.#openRaf); this.#openRaf = null; }
|
|
250
|
+
this.#uninstallFocusTrap();
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
customElements.define('feed-item-ui', AdiaFeedItem);
|
|
255
|
+
|
|
256
|
+
/* ── Static API — AdiaFeed ── */
|
|
257
|
+
|
|
258
|
+
class AdiaFeed {
|
|
259
|
+
static #containers = new Map();
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Get (or lazily create) the per-position lane. Each lane is a
|
|
263
|
+
* manual Popover-API container — `[popover="manual"]` puts it in
|
|
264
|
+
* the browser's top-layer with no z-index wars and the native
|
|
265
|
+
* popover stack lets multiple lanes coexist (e.g. one feed in
|
|
266
|
+
* top-right + another in bottom-center) without collision.
|
|
267
|
+
*/
|
|
268
|
+
static get(position = 'bottom-right') {
|
|
269
|
+
let el = AdiaFeed.#containers.get(position);
|
|
270
|
+
if (el && el.isConnected) return el;
|
|
271
|
+
el = document.createElement('feed-ui');
|
|
272
|
+
el.setAttribute('position', position);
|
|
273
|
+
if ('popover' in HTMLElement.prototype) el.setAttribute('popover', 'manual');
|
|
274
|
+
document.body.appendChild(el);
|
|
275
|
+
try { el.showPopover?.(); } catch { /* graceful fallback */ }
|
|
276
|
+
AdiaFeed.#containers.set(position, el);
|
|
277
|
+
return el;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Post a feed item. Returns a `FeedHandle` (`{id, dismiss, update}`).
|
|
282
|
+
*
|
|
283
|
+
* @param {Object} opts
|
|
284
|
+
* @param {string} [opts.text]
|
|
285
|
+
* @param {string} [opts.heading]
|
|
286
|
+
* @param {string} [opts.icon]
|
|
287
|
+
* @param {string} [opts.variant='default'] default | info | success | warning | danger
|
|
288
|
+
* @param {number|null} [opts.duration=4000] ms; null/0 = sticky (requires close click)
|
|
289
|
+
* @param {string} [opts.position='bottom-right']
|
|
290
|
+
* @param {boolean} [opts.dismissible] override default (true for sticky, false for auto)
|
|
291
|
+
* @param {string} [opts.id]
|
|
292
|
+
* @param {string} [opts.action] Phase 2 — action button label. When set,
|
|
293
|
+
* duration is forced to null (sticky); the
|
|
294
|
+
* item gets role=alertdialog + focus trap.
|
|
295
|
+
* @param {function} [opts.onAction] Phase 2 — callback invoked when the
|
|
296
|
+
* action button is pressed. Item dismisses
|
|
297
|
+
* after the callback returns.
|
|
298
|
+
*/
|
|
299
|
+
static post(opts = {}) {
|
|
300
|
+
const {
|
|
301
|
+
text = '',
|
|
302
|
+
heading = '',
|
|
303
|
+
icon = '',
|
|
304
|
+
variant = 'default',
|
|
305
|
+
duration = 4000,
|
|
306
|
+
position = 'bottom-right',
|
|
307
|
+
dismissible,
|
|
308
|
+
id,
|
|
309
|
+
action = '',
|
|
310
|
+
onAction,
|
|
311
|
+
} = opts;
|
|
312
|
+
const v = variant === 'error' ? 'danger' : variant; // documented alias
|
|
313
|
+
const container = AdiaFeed.get(position);
|
|
314
|
+
// Phase 2 max-queue: items above [max] queue with [data-queued] and
|
|
315
|
+
// become visible as visible items dismiss.
|
|
316
|
+
const max = parseInt(container.getAttribute('max') || '5', 10);
|
|
317
|
+
const visibleCount = [...container.children].filter((c) =>
|
|
318
|
+
c.tagName === 'FEED-ITEM-UI' && !c.hasAttribute('data-queued')
|
|
319
|
+
).length;
|
|
320
|
+
const item = document.createElement('feed-item-ui');
|
|
321
|
+
if (id) item.setAttribute('data-id', id);
|
|
322
|
+
item.text = text;
|
|
323
|
+
item.heading = heading;
|
|
324
|
+
item.icon = icon;
|
|
325
|
+
item.variant = v;
|
|
326
|
+
// Action-required forces sticky.
|
|
327
|
+
item.duration = action ? 0 : duration;
|
|
328
|
+
if (dismissible != null) item.dismissible = !!dismissible;
|
|
329
|
+
if (action) item.action = action;
|
|
330
|
+
if (visibleCount >= max) item.setAttribute('data-queued', '');
|
|
331
|
+
container.appendChild(item);
|
|
332
|
+
if (typeof onAction === 'function') item.update({ onAction });
|
|
333
|
+
return {
|
|
334
|
+
id: id ?? null,
|
|
335
|
+
dismiss: () => item.dismiss(),
|
|
336
|
+
update: (patch) => item.update(patch),
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/** Clear all items in a single lane. */
|
|
341
|
+
static clear(position = 'bottom-right') {
|
|
342
|
+
const el = AdiaFeed.#containers.get(position);
|
|
343
|
+
if (!el) return;
|
|
344
|
+
for (const item of [...el.children]) {
|
|
345
|
+
if (item.tagName === 'FEED-ITEM-UI') item.dismiss?.();
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/** Tear down ALL containers. Test cleanup; addresses audit L-B4. */
|
|
350
|
+
static purge() {
|
|
351
|
+
for (const el of AdiaFeed.#containers.values()) {
|
|
352
|
+
try { el.hidePopover?.(); } catch { /* noop */ }
|
|
353
|
+
el.remove();
|
|
354
|
+
}
|
|
355
|
+
AdiaFeed.#containers.clear();
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** Internal: drop a lane when its last item exits. Also rotates the
|
|
359
|
+
* Phase 2 max-queue: when a visible item leaves, promote the oldest
|
|
360
|
+
* queued sibling so the visible-count returns to [max]. */
|
|
361
|
+
static releaseContainerIfEmpty(container) {
|
|
362
|
+
if (!container) return;
|
|
363
|
+
// Promote the oldest queued sibling (if any) before deciding whether
|
|
364
|
+
// to release. The queue is FIFO; queued items live at the tail.
|
|
365
|
+
const queued = container.querySelector('feed-item-ui[data-queued]');
|
|
366
|
+
if (queued) queued.removeAttribute('data-queued');
|
|
367
|
+
if (container.children.length > 0) return;
|
|
368
|
+
try { container.hidePopover?.(); } catch { /* noop */ }
|
|
369
|
+
container.remove();
|
|
370
|
+
for (const [pos, el] of AdiaFeed.#containers) {
|
|
371
|
+
if (el === container) AdiaFeed.#containers.delete(pos);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/* Global 'feed' CustomEvent listener — same shape as AdiaFeed.post().
|
|
377
|
+
Idempotent (HMR-safe via window flag). */
|
|
378
|
+
if (typeof window !== 'undefined' && !window.__adiaFeedListenerInstalled) {
|
|
379
|
+
window.__adiaFeedListenerInstalled = true;
|
|
380
|
+
window.addEventListener('feed', (e) => {
|
|
381
|
+
if (e?.detail && typeof e.detail === 'object') AdiaFeed.post(e.detail);
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
export { AdiaFeedContainer, AdiaFeedItem, AdiaFeed };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Generated alongside feed.js — kept in sync by hand for now (feed
|
|
2
|
+
# is a Phase-1 skeleton; once it stabilizes, run the regen pipeline).
|
|
3
|
+
$schema: ../../../../scripts/schemas/component.yaml.schema.json
|
|
4
|
+
name: AdiaFeedContainer
|
|
5
|
+
tag: feed-ui
|
|
6
|
+
component: Feed
|
|
7
|
+
category: container
|
|
8
|
+
version: 1
|
|
9
|
+
description: >-
|
|
10
|
+
Shared top-layer feed channel. Per docs/specs/feed-channel.md
|
|
11
|
+
(SPEC-FEED-CHANNEL-001). Per-position singletons mounted lazily into
|
|
12
|
+
document.body via Popover API; consumers post via the static API
|
|
13
|
+
(`AdiaFeed.post()`) or the global 'feed' CustomEvent.
|
|
14
|
+
props:
|
|
15
|
+
position:
|
|
16
|
+
description: Lane the feed renders into
|
|
17
|
+
type: string
|
|
18
|
+
default: bottom-right
|
|
19
|
+
enum:
|
|
20
|
+
- top-left
|
|
21
|
+
- top-center
|
|
22
|
+
- top-right
|
|
23
|
+
- bottom-left
|
|
24
|
+
- bottom-center
|
|
25
|
+
- bottom-right
|
|
26
|
+
- inline
|
|
27
|
+
max:
|
|
28
|
+
description: Cap on simultaneously visible items per lane
|
|
29
|
+
type: number
|
|
30
|
+
default: 5
|
|
31
|
+
events: {}
|
|
32
|
+
slots: {}
|
|
33
|
+
states: {}
|
package/components/index.js
CHANGED
|
@@ -30,6 +30,7 @@ export { AdiaChat } from './chat/chat.js';
|
|
|
30
30
|
export { AdiaDrawer } from './drawer/drawer.js';
|
|
31
31
|
export { AdiaModal } from './modal/modal.js';
|
|
32
32
|
export { AdiaToast } from './toast/toast.js';
|
|
33
|
+
export { AdiaFeedContainer, AdiaFeedItem, AdiaFeed } from './feed/feed.js';
|
|
33
34
|
export { AdiaTabs } from './tabs/tabs.js';
|
|
34
35
|
export { AdiaTab } from './tabs/tab.js';
|
|
35
36
|
export { AdiaTooltip } from './tooltip/tooltip.js';
|
|
@@ -51,6 +52,7 @@ export { AdiaSkeleton } from './skeleton/skeleton.js';
|
|
|
51
52
|
export { AdiaAlert } from './alert/alert.js';
|
|
52
53
|
export { AdiaKbd } from './kbd/kbd.js';
|
|
53
54
|
export { AdiaTag } from './tag/tag.js';
|
|
55
|
+
export { AdiaSwatch } from './swatch/swatch.js';
|
|
54
56
|
export { AdiaCol } from './col/col.js';
|
|
55
57
|
export { AdiaField } from './field/field.js';
|
|
56
58
|
export { AdiaRow } from './row/row.js';
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://adiaui.dev/a2ui/v0_9/components/Swatch.json",
|
|
4
|
+
"title": "Swatch",
|
|
5
|
+
"description": "Color/style swatch primitive — a small inline tile representing a single\nvisual sample. Renders as block, dot, square, line, or dashed depending on\nshape; pairs with an optional label slot or attribute. Composed by chart-\nlegend-ui's per-row swatch and consumed directly by the token-colors /\nspacing demo pages.\n",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"allOf": [
|
|
8
|
+
{
|
|
9
|
+
"$ref": "common_types.json#/$defs/ComponentCommon"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"$ref": "common_types.json#/$defs/CatalogComponentCommon"
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"properties": {
|
|
16
|
+
"color": {
|
|
17
|
+
"description": "Swatch color. Accepts any CSS color value or var() reference. Sets the internal --swatch-color custom property; consumers can also set --swatch-color via inline style.",
|
|
18
|
+
"type": "string",
|
|
19
|
+
"default": ""
|
|
20
|
+
},
|
|
21
|
+
"component": {
|
|
22
|
+
"const": "Swatch"
|
|
23
|
+
},
|
|
24
|
+
"label": {
|
|
25
|
+
"description": "Optional label rendered next to (or below, for shape=\"block\") the swatch. Use the default slot for richer content.",
|
|
26
|
+
"type": "string",
|
|
27
|
+
"default": ""
|
|
28
|
+
},
|
|
29
|
+
"shape": {
|
|
30
|
+
"description": "Visual shape — block (filled tile), dot (small circle), square (small filled square), line (solid hairline), dashed (dashed hairline).",
|
|
31
|
+
"type": "string",
|
|
32
|
+
"enum": [
|
|
33
|
+
"block",
|
|
34
|
+
"dot",
|
|
35
|
+
"square",
|
|
36
|
+
"line",
|
|
37
|
+
"dashed"
|
|
38
|
+
],
|
|
39
|
+
"default": "square"
|
|
40
|
+
},
|
|
41
|
+
"size": {
|
|
42
|
+
"description": "Size preset — sm / md / lg. Drives the swatch's intrinsic dimensions; lg is reserved for the token-scale demo (40 px tall).",
|
|
43
|
+
"type": "string",
|
|
44
|
+
"enum": [
|
|
45
|
+
"sm",
|
|
46
|
+
"md",
|
|
47
|
+
"lg"
|
|
48
|
+
],
|
|
49
|
+
"default": "md"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"required": [
|
|
53
|
+
"component"
|
|
54
|
+
],
|
|
55
|
+
"unevaluatedProperties": false,
|
|
56
|
+
"x-adiaui": {
|
|
57
|
+
"anti_patterns": [],
|
|
58
|
+
"category": "display",
|
|
59
|
+
"events": {},
|
|
60
|
+
"examples": [
|
|
61
|
+
{
|
|
62
|
+
"description": "A single dot swatch with text label, e.g. as a chart-legend row.",
|
|
63
|
+
"a2ui": "[\n {\n \"id\": \"root\",\n \"component\": \"Swatch\",\n \"shape\": \"dot\",\n \"color\": \"var(--a-data-0)\",\n \"label\": \"Revenue\"\n }\n]",
|
|
64
|
+
"name": "basic-swatch"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"description": "Block swatch for a token-scale step.",
|
|
68
|
+
"a2ui": "[\n {\n \"id\": \"root\",\n \"component\": \"Swatch\",\n \"shape\": \"block\",\n \"size\": \"lg\",\n \"color\": \"var(--a-neutral-50)\",\n \"label\": \"50\"\n }\n]",
|
|
69
|
+
"name": "token-block"
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
"keywords": [
|
|
73
|
+
"swatch",
|
|
74
|
+
"color",
|
|
75
|
+
"chip",
|
|
76
|
+
"sample",
|
|
77
|
+
"palette",
|
|
78
|
+
"legend",
|
|
79
|
+
"step",
|
|
80
|
+
"token"
|
|
81
|
+
],
|
|
82
|
+
"name": "AdiaSwatch",
|
|
83
|
+
"related": [
|
|
84
|
+
"chart-legend-ui",
|
|
85
|
+
"tag-ui"
|
|
86
|
+
],
|
|
87
|
+
"slots": {
|
|
88
|
+
"default": {
|
|
89
|
+
"description": "Optional rich label content. When present, replaces the [label] attribute's text."
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
"states": [
|
|
93
|
+
{
|
|
94
|
+
"description": "Default, ready for display.",
|
|
95
|
+
"name": "idle"
|
|
96
|
+
}
|
|
97
|
+
],
|
|
98
|
+
"synonyms": {
|
|
99
|
+
"color-chip": [
|
|
100
|
+
"swatch",
|
|
101
|
+
"chip"
|
|
102
|
+
],
|
|
103
|
+
"color-sample": [
|
|
104
|
+
"swatch"
|
|
105
|
+
]
|
|
106
|
+
},
|
|
107
|
+
"tag": "swatch-ui",
|
|
108
|
+
"tokens": {
|
|
109
|
+
"--swatch-color": {
|
|
110
|
+
"description": "Resolved color of the swatch fill / line. Wins over the [color] attr if set inline."
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
"traits": [],
|
|
114
|
+
"version": 1
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
@scope (swatch-ui) {
|
|
2
|
+
:where(:scope) {
|
|
3
|
+
/* ── Layout ── */
|
|
4
|
+
--swatch-gap: var(--a-space-2);
|
|
5
|
+
|
|
6
|
+
/* ── Sizes ──
|
|
7
|
+
The "tile" is the coloured shape; the label is plain text rendered
|
|
8
|
+
beside (or below, for shape="block") the tile. Tile dimensions are
|
|
9
|
+
size-driven; line shapes use a fixed thickness regardless of size. */
|
|
10
|
+
--swatch-tile-sm: var(--a-space-2); /* 8px ~ */
|
|
11
|
+
--swatch-tile-md: var(--a-space-2-5); /* 10px ~ */
|
|
12
|
+
--swatch-tile-lg: 40px; /* token-scale block */
|
|
13
|
+
--swatch-line-thickness: 2px;
|
|
14
|
+
--swatch-line-length: calc(var(--swatch-tile-md) * 1.75);
|
|
15
|
+
|
|
16
|
+
/* ── Colors ──
|
|
17
|
+
Default colour falls back through the data palette so a bare
|
|
18
|
+
<swatch-ui> still renders something visible; consumers usually set
|
|
19
|
+
--swatch-color via [color] attr or inline style. */
|
|
20
|
+
--swatch-color: var(--a-data-0);
|
|
21
|
+
--swatch-label-fg: var(--a-fg-subtle);
|
|
22
|
+
|
|
23
|
+
/* ── Shape ── */
|
|
24
|
+
--swatch-radius-block: var(--a-radius-sm);
|
|
25
|
+
--swatch-radius-square: var(--a-radius-sm);
|
|
26
|
+
|
|
27
|
+
/* ── Block-shape extras (token-scale) ── */
|
|
28
|
+
--swatch-block-shadow: inset 0 0 0 1px color-mix(in oklab, currentColor 8%, transparent);
|
|
29
|
+
|
|
30
|
+
/* ── Typography ── */
|
|
31
|
+
--swatch-label-size: var(--a-ui-size);
|
|
32
|
+
--swatch-label-step-size: 10px;
|
|
33
|
+
--swatch-label-step-mt: 4px;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
:scope {
|
|
37
|
+
/* Default: inline-flex row — tile + label side-by-side, vertically
|
|
38
|
+
centered. shape="block" overrides to flex-column (label sits below
|
|
39
|
+
the tile, mimicking the token-scale step layout). */
|
|
40
|
+
box-sizing: border-box;
|
|
41
|
+
display: inline-flex;
|
|
42
|
+
align-items: center;
|
|
43
|
+
gap: var(--swatch-gap);
|
|
44
|
+
min-width: 0;
|
|
45
|
+
color: var(--swatch-label-fg);
|
|
46
|
+
font-size: var(--swatch-label-size);
|
|
47
|
+
line-height: 1.2;
|
|
48
|
+
vertical-align: baseline;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* The colored tile — sized by [size] + [shape] combinations below. */
|
|
52
|
+
:scope > [data-tile] {
|
|
53
|
+
box-sizing: border-box;
|
|
54
|
+
display: block;
|
|
55
|
+
flex-shrink: 0;
|
|
56
|
+
background: var(--swatch-color);
|
|
57
|
+
line-height: 0;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
:scope > [data-label] {
|
|
61
|
+
min-width: 0;
|
|
62
|
+
overflow: hidden;
|
|
63
|
+
text-overflow: ellipsis;
|
|
64
|
+
white-space: nowrap;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
:scope > [data-label][hidden] { display: none; }
|
|
68
|
+
|
|
69
|
+
/* ═══════ Shape: dot ═══════ */
|
|
70
|
+
:scope[shape="dot"] > [data-tile] {
|
|
71
|
+
width: var(--_size, var(--swatch-tile-md));
|
|
72
|
+
height: var(--_size, var(--swatch-tile-md));
|
|
73
|
+
border-radius: 50%;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/* ═══════ Shape: square ═══════ */
|
|
77
|
+
:scope[shape="square"] > [data-tile] {
|
|
78
|
+
width: var(--_size, var(--swatch-tile-md));
|
|
79
|
+
height: var(--_size, var(--swatch-tile-md));
|
|
80
|
+
border-radius: var(--swatch-radius-square);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/* ═══════ Shape: line (solid hairline) ═══════ */
|
|
84
|
+
:scope[shape="line"] > [data-tile] {
|
|
85
|
+
width: var(--swatch-line-length);
|
|
86
|
+
height: var(--swatch-line-thickness);
|
|
87
|
+
border-radius: var(--swatch-line-thickness);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/* ═══════ Shape: dashed (dashed hairline) ═══════ */
|
|
91
|
+
:scope[shape="dashed"] > [data-tile] {
|
|
92
|
+
width: var(--swatch-line-length);
|
|
93
|
+
height: var(--swatch-line-thickness);
|
|
94
|
+
background: transparent;
|
|
95
|
+
border-top: var(--swatch-line-thickness) dashed var(--swatch-color);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/* ═══════ Shape: block (token-scale tile) ═══════
|
|
99
|
+
Filled rectangle whose height grows with [size]; label sits BELOW
|
|
100
|
+
the tile (flex-column) so we can use it as a token-step swatch
|
|
101
|
+
without any extra wrapper. */
|
|
102
|
+
:scope[shape="block"] {
|
|
103
|
+
flex-direction: column;
|
|
104
|
+
align-items: stretch;
|
|
105
|
+
gap: 0;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
:scope[shape="block"] > [data-tile] {
|
|
109
|
+
width: 100%;
|
|
110
|
+
height: var(--_block-h, var(--swatch-tile-lg));
|
|
111
|
+
border-radius: var(--swatch-radius-block);
|
|
112
|
+
box-shadow: var(--swatch-block-shadow);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
:scope[shape="block"] > [data-label] {
|
|
116
|
+
text-align: center;
|
|
117
|
+
font-family: var(--a-font-family-code);
|
|
118
|
+
font-size: var(--swatch-label-step-size);
|
|
119
|
+
font-variant-numeric: tabular-nums;
|
|
120
|
+
color: var(--a-fg-muted);
|
|
121
|
+
margin-block-start: var(--swatch-label-step-mt);
|
|
122
|
+
white-space: nowrap;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/* ═══════ Sizes ═══════
|
|
126
|
+
Override the dot/square diameter (`--_size`) and the block-shape
|
|
127
|
+
height (`--_block-h`) for each size preset. Line/dashed widths use
|
|
128
|
+
--swatch-line-length so they stay consistent at all sizes. */
|
|
129
|
+
:scope[size="sm"] {
|
|
130
|
+
--_size: var(--swatch-tile-sm);
|
|
131
|
+
--_block-h: calc(var(--swatch-tile-lg) * 0.6);
|
|
132
|
+
}
|
|
133
|
+
:scope[size="md"] {
|
|
134
|
+
--_size: var(--swatch-tile-md);
|
|
135
|
+
--_block-h: calc(var(--swatch-tile-lg) * 0.75);
|
|
136
|
+
}
|
|
137
|
+
:scope[size="lg"] {
|
|
138
|
+
--_size: calc(var(--swatch-tile-md) * 1.4);
|
|
139
|
+
--_block-h: var(--swatch-tile-lg);
|
|
140
|
+
}
|
|
141
|
+
}
|