UNPKG

@medyll/idae-be

Version:

A modern, lightweight, and extensible DOM manipulation library built with TypeScript. Designed for precise element targeting and manipulation using a callback-based approach. Features include advanced DOM traversal, event handling, style management, attri

79 lines (78 loc) 3.35 kB
import { Be } from '../be.js'; import type { CommonHandler, HandlerCallBackFn } from '../types.js'; declare enum httpMethods { update = "update", insert = "insert" } export interface HttpHandlerHandle { update?: { url: string; options?: { method?: 'GET' | 'POST' | 'PUT' | 'DELETE'; data?: Record<string, unknown>; headers?: Record<string, string>; }; callback?: HandlerCallBackFn; }; insert?: { url: string; mode?: 'afterbegin' | 'afterend' | 'beforebegin' | 'beforeend'; callback?: HandlerCallBackFn; }; } /** * Handles HTTP operations for Be elements. */ export declare class HttpHandler implements CommonHandler<HttpHandler, HttpHandlerHandle> { private beElement; static methods: httpMethods[]; constructor(beElement: Be); methods: string[]; /** * Handles HTTP actions like loading content or inserting it into the DOM. * @param actions - The actions to perform. * @returns The Be instance for method chaining. */ handle(actions: HttpHandlerHandle): Be; /** * Loads content from a URL and updates the element's content. * Can be called with two or three arguments: * - `update(url: string, callback?: HandlerCallBackFn)` * - `update(url: string, options?: { method?: string; data?: object; headers?: object }, callback?: HandlerCallBackFn)` * * @param url - The URL to fetch content from. * @param optionsOrCallback - Optional configuration for the HTTP request or a callback function. * @param callback - Optional callback function if options are provided. * @returns The Be instance for method chaining. * @example * // Call with two arguments * be('#test').updateHttp('/content.html', ({ be }) => console.log(be.html)); * * // Call with three arguments * be('#test').updateHttp('/content.html', { method: 'POST', data: { key: 'value' } }, ({ be }) => console.log(be.html)); */ update(url: string, optionsOrCallback?: { method?: 'GET' | 'POST' | 'PUT' | 'DELETE'; data?: Record<string, unknown>; headers?: Record<string, string>; } | HandlerCallBackFn, callback?: HandlerCallBackFn): Promise<void>; /** * Loads content from a URL and inserts it into the element at a specified position. * Can be called with two or three arguments: * - `insert(url: string, callback?: HandlerCallBackFn)` * - `insert(url: string, mode?: 'afterbegin' | 'afterend' | 'beforebegin' | 'beforeend', callback?: HandlerCallBackFn)` * * @param url - The URL to fetch content from. * @param modeOrCallback - Optional position to insert the content or a callback function. * @param callback - Optional callback function if mode is provided. * @returns The Be instance for method chaining. * @example * // Call with two arguments * be('#test').insertHttp('/content.html', ({ be }) => console.log(be.html)); * * // Call with three arguments * be('#test').insertHttp('/content.html', 'afterbegin', ({ be }) => console.log(be.html)); */ insert(url: string, modeOrCallback?: 'afterbegin' | 'afterend' | 'beforebegin' | 'beforeend' | HandlerCallBackFn, callback?: HandlerCallBackFn): Promise<void>; } export {};