yukey

sw-info.ts

// The info norm's wiring: the sw-info event shape and the data-info carrier contract.
// This file is the SSOT for both.  (The norm itself: docs/precepts-we-love-the-keyboard.md,
// "info pops" -- i means "info, please" on almost any element.)
//
// One authored content, two triggers:
//
//   - `data-info="<content>"` on any element makes it a CARRIER.  sw-infopop's
//     hover trigger finds carriers by this attribute, and the megacolumn
//     controller answers otherwise-unclaimed i forwards for them.  Components
//     with an info property (sw-button) mirror it onto this attribute;
//     plain markup writes the attribute directly.  Empty means not a carrier.
//   - `sw-info` (bubbles + composed) is the keyboard trigger's event: a producer
//     that answered i dispatches it, sw-infopop renders it.  The detail carries
//     the anchor element because composed events retarget: a listener outside
//     the shadow tree sees only the host chain, never the real source.
//
// Producers today: sw-button (its own i claim, standalone and in rows) and
// MegacolumnController (the fallback for plain [data-info] rows).

export interface SwInfoDetail {
	content: string;
	// The element to anchor the popup to (see the retargeting note above).
	source: HTMLElement;
}

export function dispatchSwInfo(source: HTMLElement, content: string): void {
	source.dispatchEvent(
		new CustomEvent<SwInfoDetail>("sw-info", {
			detail: { content, source },
			bubbles: true,
			composed: true,
		}),
	);
}

packages/yukey/src/sw-info.ts · 1.5 KiB · f2166ce42f