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

77 lines (76 loc) 3.04 kB
import { Be } from '../be.js'; import type { CommonHandler } from '../types.js'; declare enum attrMethods { set = "set", get = "get", delete = "delete" } export type AttrHandlerHandle = { set: AttrHandler['set']; get: AttrHandler['get']; delete: AttrHandler['delete']; }; /** * Handles attribute operations for Be elements. */ export declare class AttrHandler implements CommonHandler<AttrHandler, AttrHandler> { private beElement; static methods: attrMethods[]; /** * Initializes the AttrHandler with a Be element. * @param element - The Be element to operate on. */ constructor(element: Be); methods: string[] | keyof AttrHandler; /** * Handles dynamic method calls for attribute operations. * @param actions - The actions to perform (e.g., set, get, delete). * @returns The Be element for chaining. */ handle(actions: Partial<AttrHandlerHandle>): Be; /** * Retrieves the value of an attribute. * @param name - The name of the attribute to retrieve. * @returns The value of the attribute, or `null` if not found. * @example * // HTML: <div id="test" data-role="admin"></div> * const beInstance = be('#test'); * const role = beInstance.getAttr('data-role'); * console.log(role); // Output: "admin" */ get(name?: string): string | null; /** * Sets one or more attributes on the element(s). * @param nameOrObject - A key-value pair or an object containing multiple key-value pairs. * @param value - The value to set if a single key is provided. * @returns The Be element for chaining. * @example * // HTML: <div id="test"></div> * const beInstance = be('#test'); * beInstance.setAttr('data-role', 'admin'); // Sets a single attribute * beInstance.setAttr({ class: 'highlight', title: 'Hello' }); // Sets multiple attributes */ set(nameOrObject: string | Record<string, string>, value?: string): Be; /** * Deletes one or more attributes from the element(s). * @param nameOrObject - A key or an object containing multiple keys to delete. * @returns The Be element for chaining. * @example * // HTML: <div id="test" data-role="admin" class="highlight"></div> * const beInstance = be('#test'); * beInstance.deleteAttr('data-role'); // Deletes a single attribute * beInstance.deleteAttr({ class: '' }); // Deletes multiple attributes */ delete(nameOrObject: string | Record<string, string>): Be; /** * Retrieves all attributes as a key-value pair object. * @returns An object containing all attributes, or `null` if not applicable. * @example * // HTML: <div id="test" data-role="admin" class="highlight"></div> * const beInstance = be('#test'); * const attributes = beInstance.attrs.valueOf(); * console.log(attributes); // Output: { id: "test", "data-role": "admin", class: "highlight" } */ valueOf(): Record<string, string> | null; } export {};