/** * Copy component: one delegated listener per root. * * @augments IvComponent */ export class Copy extends IvComponent { /** @type {Readonly} */ static defaults: Readonly; /** * Returns the instance attached to `el`, if any. * * @param {Element} el Host element. * @returns {Copy|undefined} The instance or `undefined`. */ static get(el: Element): Copy | undefined; /** * Returns the existing instance or creates one. * * @param {Element} el Host element. * @param {Partial} [options] Options passed in JavaScript. * @returns {Copy} The instance. */ static getOrCreate(el: Element, options?: Partial): Copy; /** * Instantiates every `[data-iv-component="copy"]` inside `root`. * * @param {ParentNode} [root] Subtree to scan. * @returns {Copy[]} Newly created instances. */ static initAll(root?: ParentNode): Copy[]; /** * @param {Element} el Root that holds one or more copy buttons. * @param {Partial} [options] Options passed in JavaScript. */ constructor(el: Element, options?: Partial); /** @type {HTMLElement|null} Live region announcing the result. */ _status: HTMLElement | null; /** @type {Map }>} Buttons showing feedback. */ _busy: Map; }>; /** * Resolved options. * * @returns {Readonly} The options. */ get options(): Readonly; /** * The text a trigger copies: the element named by its selector, or the * code of the nearest `.iv-code`. * * @param {Element} trigger Button carrying `data-iv-copy`. * @returns {string|null} The text, or `null` when there is nothing to copy. */ textOf(trigger: Element): string | null; /** * Copies the text of `trigger`. Emits the cancelable `iv:copy` first and * `iv:copied` with `ok` once the clipboard answered. * * @param {HTMLElement} trigger Button carrying `data-iv-copy`. * @returns {Promise} Whether the text reached the clipboard. */ copy(trigger: HTMLElement): Promise; /** * Where the clipboard refused, the text is selected so the keyboard * shortcut the feedback names copies it. * * @param {Element} trigger Button carrying `data-iv-copy`. * @returns {void} */ _select(trigger: Element): void; /** * Shows the result on the button and in the live region. * * @param {HTMLElement} button The trigger. * @param {boolean} ok Whether the copy succeeded. * @returns {void} */ _feedback(button: HTMLElement, ok: boolean): void; /** * Writes `message` into a polite live region owned by this instance. * * @param {string} message Text to announce. * @returns {void} */ _announce(message: string): void; } export type CopyOptions = { /** * Label shown after a successful copy. */ copiedText: string; /** * Label shown when the clipboard refused. */ failedText: string; /** * Milliseconds the feedback stays. */ timeout: number; }; import { IvComponent } from "../core/component.js";