import { Base, type BaseConfig, type BaseProps, BaseInterface } from '@studiometa/js-toolkit'; export interface FetchProps extends BaseProps { $el: HTMLAnchorElement | HTMLFormElement; $refs: { headers: HTMLInputElement[]; }; $options: { history: boolean; requestInit: RequestInit; headers: Record; mode: 'replace' | 'prepend' | 'append' | 'morph'; selector: string; response: string; viewTransition: boolean; }; } export type FetchConstructor = { new (...args: any[]): T; prototype: Fetch; } & Pick; /** * Fetch class. * @link https://ui.studiometa.dev/components/Fetch/ */ export declare class Fetch extends Base implements BaseInterface { /** * Declare the `this.constructor` type * @link https://github.com/microsoft/TypeScript/issues/3841#issuecomment-2381594311 */ ['constructor']: FetchConstructor; /** * Fetch events enum. */ static FETCH_EVENTS: { readonly BEFORE_FETCH: 'fetch-before'; readonly FETCH: 'fetch-fetch'; readonly RESPONSE: 'fetch-response'; readonly AFTER_FETCH: 'fetch-after'; readonly BEFORE_UPDATE: 'fetch-update-before'; readonly UPDATE: 'fetch-update'; readonly AFTER_UPDATE: 'fetch-update-after'; readonly ERROR: 'fetch-error'; readonly ABORT: 'fetch-abort'; }; /** * Fetch modes enum. */ static FETCH_MODES: { readonly REPLACE: 'replace'; readonly PREPEND: 'prepend'; readonly APPEND: 'append'; readonly MORPH: 'morph'; }; /** * Config. */ static config: BaseConfig; /** * Header names used by the requestInit property. * @internal */ __headerNames: { readonly ACCEPT: 'accept'; readonly X_REQUESTED_BY: 'x-requested-by'; readonly X_TRIGGERED_BY: 'x-triggered-by'; readonly USER_AGENT: 'user-agent'; }; /** * DOM Parser to parse the new content to be injected. * @internal */ __domParser: DOMParser; /** * Abort controller to prevent multiple simultaneous fetches. * @internal */ __abortController: AbortController; /** * Client. * @internal */ __client: typeof fetch; /** * The client used for the fetch request. */ get client(): typeof fetch; /** * The URL to use for the request. */ get url(): URL; /** * Option for the fetch request. */ get requestInit(): RequestInit; /** * Is the root element a link? */ get isLink(): boolean; /** * Is the root element a form? */ get isForm(): boolean; /** * Emit bubbling events. * @inheritdoc */ $emit(event: string, ...args: unknown[]): void; /** * If root element is a link, prevent its default behavior and fetch its URL. */ onClick({ event }: { event: MouseEvent; }): void; /** * If root element is a form, prevent its default behavior on submit and fetch its action * following the `method` attribute and with the form's data. */ onSubmit({ event }: { event: SubmitEvent; }): void; /** * Update content on history back/forward navigation. */ onWindowPopstate(): void; /** * Fetch given url. */ fetch(url: URL, requestInit?: RequestInit): Promise; /** * Update the DOM with new content from the fetched HTML. * @internal */ __updateDOM(fragment: Document): void; /** * Dispatch the contents to update to their matching FrameTarget. */ update(url: URL, requestInit: RequestInit, content: string): Promise; /** * Handle errors. */ error(url: URL, requestInit: RequestInit, error: Error): void; /** * Abort the current request. */ abort(reason?: any): void; }