@esri/calcite-components
Version:
Web Components for Esri's Calcite Design System.
91 lines (90 loc) • 2.9 kB
JavaScript
/*! All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://github.com/Esri/calcite-design-system/blob/dev/LICENSE.md for details.
v3.2.1 */
import { isServer } from "lit";
import { n as nodeListToArray } from "./dom.js";
const ComboboxItemSelector = "CALCITE-COMBOBOX-ITEM";
const ComboboxItemGroupSelector = "CALCITE-COMBOBOX-ITEM-GROUP";
const AllComboboxChildrenSelector = `${ComboboxItemSelector}, ${ComboboxItemGroupSelector}`;
const CSS = {
allSelected: "all-selected",
chip: "chip",
chipInvisible: "chip--invisible",
icon: "icon",
input: "input",
inputHidden: "input--hidden",
label: "label",
labelIcon: "label--icon",
listContainer: "list-container",
placeholderIcon: "placeholder-icon",
selectAll: "select-all",
selectionDisplayFit: "selection-display--fit",
selectionDisplaySingle: "selection-display--single",
selectedIcon: "selected-icon",
floatingUIContainer: "floating-ui-container",
screenReadersOnly: "screen-readers-only",
wrapper: "wrapper",
wrapperSingle: "wrapper--single",
wrapperActive: "wrapper--active"
};
const IDS = {
validationMessage: "comboboxValidationMessage"
};
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 || item.textLabel;
}
export {
CSS as C,
IDS as I,
getDepth as a,
ComboboxItemSelector as b,
ComboboxItemGroupSelector as c,
getLabel as d,
getItemAncestors as e,
getItemChildren as f,
getAncestors as g,
hasActiveChildren as h,
isSingleLike as i
};