@atlaskit/editor-common
Version:
A package that contains common classes and components for editor and renderer
41 lines (40 loc) • 1.73 kB
TypeScript
/**
* Walks a DOM tree up to the provided `stopElement`, or if falsy before.
* @param element
* @param stopElement
*/
export declare function walkUpTreeUntil(element: HTMLElement, shouldStop: (element: HTMLElement) => boolean): HTMLElement;
/**
* Takes all children out from wrapped el and puts them directly inside
* the parent el, at the wrapped el's position
*/
export declare function unwrap(parent: HTMLElement, wrapped: HTMLElement): void;
/**
* Walks up DOM removing elements if they are empty until it finds
* one that is not
*/
export declare function removeNestedEmptyEls(el: HTMLElement): void;
/**
* IE11 doesn't support classList to SVGElements
**/
export declare const containsClassName: (node: HTMLElement | SVGElement | null, className: string) => boolean;
export declare function closest(node: HTMLElement | null | undefined, s: string): HTMLElement | null;
export declare function closestElement(node: HTMLElement | null | undefined, s: string): HTMLElement | null;
/**
* Util for converting a css pixel size value to a number (of pixels).
*
* ie.
* ```ts
* const pixels = parsePx('10px')
* // ^$ const pixels: number
* ```
* * ```ts
* const pixels = parsePx('10')
* // ^$ const pixels: number | undefined
* ```
*/
export declare function parsePx<PXString extends `${number}px`>(pxStr: PXString): number;
export declare function parsePx<PXString extends string>(pxStr: PXString): number | undefined;
export type MapCallback<T, S> = (elem: S, idx: number, parent: Element) => T;
export declare function mapElem<T>(elem: Element, callback: MapCallback<T, Element>): Array<T>;
export declare function maphElem<T, U extends HTMLElement>(elem: U, callback: MapCallback<T, U>): Array<T>;