ext(affordances): wireFillFromTab + .glyph-btn CSS

This commit is contained in:
adlee-was-taken
2026-05-01 17:04:17 -04:00
parent 918fdef519
commit 4be0bcff83
4 changed files with 130 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
import { GLYPH_FILL_FROM_TAB } from '../glyphs';
export interface FillFromTabOpts {
sendMessage: (msg: { type: 'get_active_tab_url' }) => Promise<{ ok: boolean; data?: { url: string; title: string } | null }>;
}
export function wireFillFromTab(form: HTMLElement, opts: FillFromTabOpts): void {
const btn = form.querySelector<HTMLButtonElement>('#fill-from-tab-btn');
if (!btn) return;
btn.addEventListener('click', async () => {
const resp = await opts.sendMessage({ type: 'get_active_tab_url' });
if (!resp.ok || !resp.data) {
btn.disabled = true;
btn.title = 'no active tab';
return;
}
const urlEl = form.querySelector<HTMLInputElement>('#f-url');
const titleEl = form.querySelector<HTMLInputElement>('#f-title');
if (urlEl) urlEl.value = resp.data.url;
if (titleEl && !titleEl.value.trim()) titleEl.value = resp.data.title;
});
}
export const FILL_FROM_TAB_BTN_HTML = `<button id="fill-from-tab-btn" class="glyph-btn" type="button" title="fill from active tab">${GLYPH_FILL_FROM_TAB}</button>`;