UNPKG

@esri/calcite-components

Version:

Web Components for Esri's Calcite Design System.

59 lines (58 loc) 1.9 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */ import { isServer } from "lit"; import { n as nodeListToArray } from "./dom.js"; import { A as AllComboboxChildrenSelector, a as ComboboxItemSelector, b as ComboboxItemGroupSelector } from "./resources5.js"; function getAncestors(element) { const parent = element.parentElement?.closest(AllComboboxChildrenSelector); const grandparent = parent?.parentElement?.closest(AllComboboxChildrenSelector); return [parent, grandparent].filter((el) => !!el); } function getItemAncestors(item) { return item.ancestors?.filter((el) => el.nodeName === "CALCITE-COMBOBOX-ITEM") || []; } function getItemChildren(item) { return nodeListToArray(item.querySelectorAll("calcite-combobox-item")); } function hasActiveChildren(node) { const items = nodeListToArray(node.querySelectorAll("calcite-combobox-item")); return items.filter((item) => item.selected).length > 0; } function getDepth(element) { if (isServer) { return 0; } const result = document.evaluate( "ancestor::calcite-combobox-item | ancestor::calcite-combobox-item-group", element, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null ); const depth = result.snapshotLength; if (depth > 0 && element.nodeName === ComboboxItemSelector) { for (let i = 0; i < depth; i++) { const parent = result.snapshotItem(i); if (parent.nodeName === ComboboxItemGroupSelector) { return depth; } } } else if (element.nodeName === ComboboxItemGroupSelector) { return depth; } return depth + 1; } function isSingleLike(selectionMode) { return selectionMode.includes("single"); } function getLabel(item) { return item.shortHeading || item.heading; } export { getItemAncestors as a, getItemChildren as b, getAncestors as c, getDepth as d, getLabel as g, hasActiveChildren as h, isSingleLike as i };