You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
974 B
33 lines
974 B
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.getParentElement = exports.isHostElement = void 0;
|
|
/**
|
|
* Checks if the given element is a host element.
|
|
* @param element The element to check.
|
|
*/
|
|
function isHostElement(element) {
|
|
return typeof element?.type === 'string';
|
|
}
|
|
exports.isHostElement = isHostElement;
|
|
/**
|
|
* Returns first host ancestor for given element or first ancestor of one of
|
|
* passed component types.
|
|
*
|
|
* @param element The element start traversing from.
|
|
* @param componentTypes Additional component types to match.
|
|
*/
|
|
function getParentElement(element, componentTypes = []) {
|
|
if (element == null) {
|
|
return null;
|
|
}
|
|
let current = element.parent;
|
|
while (current) {
|
|
if (isHostElement(current) || componentTypes.includes(current.type)) {
|
|
return current;
|
|
}
|
|
current = current.parent;
|
|
}
|
|
return null;
|
|
}
|
|
exports.getParentElement = getParentElement;
|