utils2.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*!
  2. * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
  4. * v1.0.0-beta.97
  5. */
  6. import { n as nodeListToArray } from './dom.js';
  7. import { Build } from '@stencil/core/internal/client/index.js';
  8. const ComboboxItem = "CALCITE-COMBOBOX-ITEM";
  9. const ComboboxItemGroup = "CALCITE-COMBOBOX-ITEM-GROUP";
  10. const ComboboxChildSelector = `${ComboboxItem}, ${ComboboxItemGroup}`;
  11. const TEXT = {
  12. removeTag: "Remove tag"
  13. };
  14. function getAncestors(element) {
  15. var _a, _b;
  16. const parent = (_a = element.parentElement) === null || _a === void 0 ? void 0 : _a.closest(ComboboxChildSelector);
  17. const grandparent = (_b = parent === null || parent === void 0 ? void 0 : parent.parentElement) === null || _b === void 0 ? void 0 : _b.closest(ComboboxChildSelector);
  18. return [parent, grandparent].filter((el) => el);
  19. }
  20. function getItemAncestors(item) {
  21. var _a;
  22. return (((_a = item.ancestors) === null || _a === void 0 ? void 0 : _a.filter((el) => el.nodeName === "CALCITE-COMBOBOX-ITEM")) || []);
  23. }
  24. function getItemChildren(item) {
  25. return nodeListToArray(item.querySelectorAll("calcite-combobox-item"));
  26. }
  27. function hasActiveChildren(node) {
  28. const items = nodeListToArray(node.querySelectorAll("calcite-combobox-item"));
  29. return items.filter((item) => item.selected).length > 0;
  30. }
  31. function getDepth(element) {
  32. if (!Build.isBrowser) {
  33. return 0;
  34. }
  35. const result = document.evaluate("ancestor::calcite-combobox-item | ancestor::calcite-combobox-item-group", element, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  36. return result.snapshotLength;
  37. }
  38. export { ComboboxItemGroup as C, TEXT as T, ComboboxChildSelector as a, getItemChildren as b, ComboboxItem as c, getAncestors as d, getDepth as e, getItemAncestors as g, hasActiveChildren as h };