@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
119 lines (118 loc) • 4.67 kB
TypeScript
import { Be } from '../be.js';
import type { HandlerCallbackProps, HandlerCallBackFn, CommonHandler } from '../types.js';
declare enum textMethods {
update = "update",
append = "append",
prepend = "prepend",
remove = "remove",
wrap = "wrap",
normalize = "normalize",
replace = "replace",
clear = "clear"
}
export type TextHandlerHandle = {
update?: string | HTMLElement;
append?: string | HTMLElement;
prepend?: string | HTMLElement;
remove?: boolean;
replace?: string | HTMLElement;
wrap?: string | HTMLElement;
normalize?: boolean;
clear?: boolean;
callback?: (element: HandlerCallbackProps) => void;
};
export declare class TextHandler implements CommonHandler<TextHandler> {
private beElement;
static methods: textMethods[];
constructor(element: Be);
methods: string[] | keyof TextHandler;
get text(): string | null;
handle(actions: TextHandlerHandle): Be;
/**
* Updates the text content of the element(s).
* @param content - The new text content to set.
* @param callback - Optional callback function.
* @returns The Be instance for method chaining.
* @example
* // HTML: <div id="test">Original</div>
* const beInstance = be('#test');
* beInstance.updateText('Updated'); // Updates the text content to "Updated"
*/
update(content: TextHandlerHandle['update'], callback?: HandlerCallBackFn): Be;
/**
* Appends text content to the element(s).
* @param content - The text content to append.
* @param callback - Optional callback function.
* @returns The Be instance for method chaining.
* @example
* // HTML: <div id="test">Original</div>
* const beInstance = be('#test');
* beInstance.appendText(' Appended'); // Appends " Appended" to the text content
*/
append(content: TextHandlerHandle['append'], callback?: HandlerCallBackFn): Be;
/**
* Prepends text content to the element(s).
* @param content - The text content to prepend.
* @param callback - Optional callback function.
* @returns The Be instance for method chaining.
* @example
* // HTML: <div id="test">Original</div>
* const beInstance = be('#test');
* beInstance.prependText('Prepended '); // Prepends "Prepended " to the text content
*/
prepend(content: TextHandlerHandle['prepend'], callback?: HandlerCallBackFn): Be;
/**
* Replaces the text content of the element(s).
* @param content - The new text content to replace with.
* @param callback - Optional callback function.
* @returns The Be instance for method chaining.
* @example
* // HTML: <div id="test">Original</div>
* const beInstance = be('#test');
* beInstance.replaceText('Replaced'); // Replaces the text content with "Replaced"
*/
replace(content: TextHandlerHandle['replace'], callback?: HandlerCallBackFn): Be;
/**
* Removes the element(s) from the DOM.
* @param callback - Optional callback function.
* @returns The Be instance for method chaining.
* @example
* // HTML: <div id="test">To be removed</div>
* const beInstance = be('#test');
* beInstance.removeText(); // Removes the element
*/
remove(callback?: HandlerCallBackFn): Be;
/**
* Clears the text content of the element(s).
* @param callback - Optional callback function.
* @returns The Be instance for method chaining.
* @example
* // HTML: <div id="test">Content</div>
* const beInstance = be('#test');
* beInstance.clearText(); // Clears the text content
*/
clear(callback?: HandlerCallBackFn): Be;
/**
* Normalizes the text content of the element(s).
* @param callback - Optional callback function.
* @returns The Be instance for method chaining.
* @example
* // HTML: <div id="test">Text <span>Fragment</span> Text</div>
* const beInstance = be('#test');
* beInstance.normalizeText(); // Normalizes the text content
*/
normalize(callback?: HandlerCallBackFn): Be;
/**
* Wraps the element(s) with a new element.
* @param content - The wrapper element as a string or HTMLElement.
* @param callback - Optional callback function.
* @returns The Be instance for method chaining.
* @example
* // HTML: <div id="test">Content</div>
* const beInstance = be('#test');
* beInstance.wrapText('<div class="wrapper"></div>'); // Wraps the element with a <div>
*/
wrap(content: TextHandlerHandle['wrap'], callback?: HandlerCallBackFn): Be;
valueOf(): string | null;
}
export {};