obsidian-dev-utils
Version:
This is the collection of useful functions that you can use for your Obsidian plugin development
74 lines (73 loc) • 2.31 kB
text/typescript
/**
* @packageDocumentation
*
* Helpers for working with HTML elements.
*/
/**
* A HTML element that can be validated.
*/
export interface ValidatorElement extends HTMLElement {
/**
* Checks the validity of the element.
*
* @returns True if the element is valid, false otherwise.
*/
checkValidity(): boolean;
/**
* Reports the validity of the element.
*/
reportValidity(): boolean;
/**
* Sets a custom error message on the element.
*
* @param error - The error message to set on the element.
*/
setCustomValidity(error: string): void;
/**
* An error message of the element.
*/
readonly validationMessage: string;
}
/**
* Appends a code block to the given DocumentFragment or HTMLElement.
*
* @param el - The DocumentFragment or HTMLElement to append the code block to.
* @param code - The code to be displayed in the code block.
*/
export declare function appendCodeBlock(el: DocumentFragment | HTMLElement, code: string): void;
/**
* Ensures that the given element is loaded.
*
* @param el - The element to ensure is loaded.
* @returns A {@link Promise} that resolves when the element is loaded.
*/
export declare function ensureLoaded(el: Element): Promise<void>;
/**
* Checks if the element is visible in the offset parent.
*
* @param el - The element to check.
* @returns True if the element is visible in the offset parent, false otherwise.
*/
export declare function isElementVisibleInOffsetParent(el: HTMLElement): boolean;
/**
* Checks if the element is loaded.
*
* @param el - The element to check.
* @returns True if the element is loaded, false otherwise.
*/
export declare function isLoaded(el: Element): boolean;
/**
* Adds an event listener to the ancestor nodes of the given node.
*
* @param node - The node to add the event listener to.
* @param callback - The callback to call when the event is triggered.
* @returns A function to remove the event listener.
*/
export declare function onAncestorScrollOrResize(node: Node, callback: () => void): () => void;
/**
* Converts a number to a string with 'px' appended.
*
* @param value - The number to convert.
* @returns The number as a string with 'px' appended.
*/
export declare function toPx(value: number): string;