Outlook_Addin_LLM/node_modules/@fluentui/dom-utilities/lib/getParent.js

33 lines
1.1 KiB
JavaScript
Raw Normal View History

import { getVirtualParent } from './getVirtualParent';
/**
* Gets the element which is the parent of a given element.
* If `allowVirtuaParents` is `true`, this method prefers the virtual parent over
* real DOM parent when present.
*
* @public
*/
export function getParent(child, allowVirtualParents) {
var _a, _b;
if (allowVirtualParents === void 0) { allowVirtualParents = true; }
if (!child) {
return null;
}
var parent = allowVirtualParents && getVirtualParent(child);
if (parent) {
return parent;
}
// Support looking for parents in shadow DOM
if (typeof child.assignedElements !== 'function' && ((_a = child.assignedSlot) === null || _a === void 0 ? void 0 : _a.parentNode)) {
// Element is slotted
return child.assignedSlot;
}
else if (((_b = child.parentNode) === null || _b === void 0 ? void 0 : _b.nodeType) === 11) {
// nodeType 11 is DOCUMENT_FRAGMENT
// Element is in shadow root
return child.parentNode.host;
}
else {
return child.parentNode;
}
}
//# sourceMappingURL=getParent.js.map