UNPKG

@esri/calcite-components

Version:

Web Components for Esri's Calcite Design System.

1 lines 4.03 kB
import{h as t,H as s}from"./p-ff68592a.js";import{f as i,c as n,g as e,a as r}from"./p-fbd3d700.js";import{d as a}from"./p-fc8feabd.js";import{g as o}from"./p-0ae16e31.js";import{C as c}from"./p-39515aa9.js";function h(){this.setUpItems(),this.setUpFilter()}const l=["ArrowUp","ArrowDown"];function f(){this.setUpItems(),this.setUpFilter(),this.emitCalciteListChange=a(j.bind(this),0)}function u(){this.observer.observe(this.el,{childList:!0,subtree:!0})}function d(){this.observer.disconnect()}function m(t){const{selectedValues:s}=this,{item:i,value:n,selected:e,shiftPressed:r}=t.detail;e?(this.multiple||this.deselectSiblingItems(i),this.multiple&&r&&this.selectSiblings(i),s.set(n,i)):(s.delete(n),this.multiple&&r&&this.selectSiblings(i,!0)),this.multiple||A(i,e),this.lastSelectedItem=i,this.emitCalciteListChange()}function p(t){t.stopPropagation();const s=t.detail.oldValue,i=this.selectedValues;if(i.has(s)){const n=i.get(s);i.delete(s),i.set(t.detail.newValue,n)}}function b(t){const{key:s,target:n}=t;if(!function(t){return!!l.find((s=>s===t))}(s))return;const{items:e,multiple:r}=this,{length:a}=e,c=e.indexOf(n);if(!a||-1===c)return;t.preventDefault();const h=e[o(c+("ArrowUp"===s?-1:1),a)];A(h,!0),i(h),r||(h.selected=!0)}function j(){this.calciteListChange.emit(this.selectedValues)}function g(t){if(t.defaultPrevented)return;const s=t.target,i=this.selectedValues;"CALCITE-PICK-LIST-GROUP"===s.parentElement.tagName?(s.parentElement.remove(),Array.from(s.parentElement.children).forEach((t=>i.delete(t.value)))):(s.remove(),i.delete(s.value)),this.emitCalciteListChange()}function A(t,s){s?t.removeAttribute("tabindex"):t.setAttribute("tabindex","-1")}function v(){const{multiple:t,items:s}=this;if(0===s.length)return;if(t)return s[0].setFocus();return(s.find((t=>t.selected))||s[0]).setFocus()}function y(t){this.items=Array.from(this.el.querySelectorAll(t));let s=!1;const{items:i}=this;i.forEach((t=>{t.icon=this.getIconType(),this.multiple||(t.disableDeselect=!0,A(t,!1)),t.selected&&(s=!0,A(t,!0),this.selectedValues.set(t.value,t))}));const[n]=i;!s&&n&&A(n,!0)}function C(t){this.items.forEach((s=>{s.value!==t.value&&(s.toggleSelected(!1),this.selectedValues.has(s.value)&&this.selectedValues.delete(s.value))}))}function O(t,s=!1){if(!this.lastSelectedItem)return;const{items:i}=this,n=i.findIndex((t=>t.value===this.lastSelectedItem.value)),e=i.findIndex((s=>s.value===t.value));i.slice(Math.min(n,e),Math.max(n,e)).forEach((t=>{t.toggleSelected(!s),s?this.selectedValues.delete(t.value):this.selectedValues.set(t.value,t)}))}let w;function F(t){const s=t.detail.map((t=>t.value));w||(w=new Set);const i=this.items.filter((t=>{const i=t.parentElement;i.matches("calcite-pick-list-group")&&w.add(i);const n=s.includes(t.value);return t.hidden=!n,n}));w.forEach((t=>{const s=i.some((s=>t.contains(s)));if(t.hidden=!s,!s)return;const e=n(t,"parent-item");e&&(e.hidden=!1,i.includes(e)&&Array.from(t.children).forEach((t=>t.hidden=!1)))})),w.clear()}function L(){return this.items.map((t=>({label:t.label,description:t.description,metadata:t.metadata,value:t.value})))}const P=i=>{var{props:{disabled:n,loading:a,filterEnabled:o,dataForFilter:h,handleFilter:l,filterPlaceholder:f,el:u}}=i,d=function(t,s){var i={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&s.indexOf(n)<0&&(i[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var e=0;for(n=Object.getOwnPropertySymbols(t);e<n.length;e++)s.indexOf(n[e])<0&&Object.prototype.propertyIsEnumerable.call(t,n[e])&&(i[n[e]]=t[n[e]])}return i}(i,["props"]);const m=t("slot",null);return t(s,Object.assign({"aria-busy":a.toString(),"aria-disabled":n.toString(),role:"menu"},d),t("section",null,t("header",{class:{[c.sticky]:!0}},o?t("calcite-filter",{"aria-label":f,data:h,dir:e(u),onCalciteFilterChange:l,placeholder:f}):null,t("slot",{name:"menu-actions"})),a||n?t("calcite-scrim",{loading:a,theme:r(u)},m):m))};export{P as L,u as a,m as b,d as c,C as d,p as e,y as f,L as g,F as h,f as i,v as j,b as k,h as m,g as r,O as s}