UNPKG

@esri/calcite-components

Version:

Web Components for Esri's Calcite Design System.

5 lines 2.01 kB
/*! * All material copyright ESRI, All Rights Reserved, unless otherwise specified. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details. */ import{q as n,c as e}from"./p-8f3a3e4e.js";const t="calciteInternalLabelConnected",c="calciteInternaLabelDisconnected",o=new WeakMap,a=new Set;function l(t){const c=(t=>{const{id:c}=t,o=c&&n(t,{selector:`calcite-label[for="${c}"]`});if(o)return o;const a=e(t,"calcite-label");return!a||function(n,e){let t;const c="custom-element-ancestor-check",o=c=>{c.stopImmediatePropagation();const o=c.composedPath();t=o.slice(o.indexOf(e),o.indexOf(n))};return n.addEventListener(c,o,{once:!0}),e.dispatchEvent(new CustomEvent(c,{composed:!0,bubbles:!0})),n.removeEventListener(c,o),t.filter((t=>t!==e&&t!==n)).filter((n=>{var e;return null===(e=n.tagName)||void 0===e?void 0:e.includes("-")})).length>0}(a,t)?null:a})(t.el);if(o.has(c))return;const l=u.bind(t),i=d.bind(t);c?((()=>{t.labelEl=c;const n=r.bind(t);o.set(t.labelEl,n),t.labelEl.addEventListener("calciteInternalLabelClick",n)})(),a.delete(t),document.removeEventListener("calciteInternalLabelConnected",l),document.addEventListener("calciteInternaLabelDisconnected",i)):c||a.has(t)||(i(),document.removeEventListener("calciteInternaLabelDisconnected",i))}function i(n){const e=u.bind(n),t=d.bind(n);if(a.delete(n),document.removeEventListener("calciteInternalLabelConnected",e),document.removeEventListener("calciteInternaLabelDisconnected",t),!n.labelEl)return;const c=o.get(n.labelEl);n.labelEl.removeEventListener("calciteInternalLabelClick",c),o.delete(n.labelEl)}function s(n){var e,t;return n.label||(null===(t=null===(e=n.labelEl)||void 0===e?void 0:e.textContent)||void 0===t?void 0:t.trim())||""}function r(n){this.disabled||this.el.contains(n.detail.sourceEvent.target)||this.onLabelClick(n)}function u(){a.has(this)&&l(this)}function d(){a.add(this);const n=u.bind(this);document.addEventListener("calciteInternalLabelConnected",n)}export{c as a,l as c,i as d,s as g,t as l}