@atlaskit/editor-common
Version:
A package that contains common classes and components for editor and renderer
46 lines (45 loc) • 2.29 kB
TypeScript
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
/**
* Finds the direct child of the ProseMirror root element that contains the current selection.
*
* Starting from the DOM node at the selection position, this function walks up the DOM tree
* until it reaches the ProseMirror root, then returns the last element before the root
* (i.e., the second top-level ancestor).
*
* This is useful for attaching MutationObservers to the narrowest subtree that contains
* the selection, while still capturing all relevant mutations within that branch.
*
* @param editorView - The ProseMirror EditorView instance
* @returns The direct child of PM root containing the selection, or null if not found
*/
export declare const getSelectionAncestorDOM: (editorView?: EditorView) => HTMLElement | null;
/**
* Checks if a given node contains a popup with a nested element identified by a specific test ID.
*
* @param node - The node to check.
* @param nestedElementQuery - The query to look for the nested element.
* @returns True if the node contains the popup, false otherwise.
*/
export declare const containsPopupWithNestedElement: (node: Node | null | undefined, nestedElementQuery: string) => boolean;
/**
* Returns the popup with a nested element identified by a specific test ID if it exists.
*
* @param node - The node to check.
* @param nestedElementQuery - The query to look for the nested element.
* @returns Element if the node contains the popup, undefined otherwise.
*/
export declare const popupWithNestedElement: (node: Node | null | undefined, nestedElementQuery: string) => Element | null | undefined;
/**
* Searches for the popup container element relative to the provided editor view element.
*
* @param editorViewEl - The editor view HTMLElement.
* @returns The popup container HTMLElement if found, otherwise undefined.
*/
export declare const getPopupContainerFromEditorView: (editorViewEl?: HTMLElement | null) => HTMLElement | undefined;
/**
* Checks if a node matches or contains the node given by the provided query css selector
*
* @param query - CSS selector string
* @returns true if node matches or contains query or false otherwise
*/
export declare const getNodeQuery: (query: string) => (node?: Node | null) => boolean;