@adyen/adyen-platform-experience-web
Version:

34 lines (33 loc) • 1.07 kB
JavaScript
import { CONTROL_ELEMENT_PROPERTY as p } from "../../../../hooks/element/useClickOutside.js";
const u = /* @__PURE__ */ (() => {
let e = [];
const r = (n) => {
if (n.some(
(l) => l instanceof Element && e.some((s) => {
const c = s.element[p];
return c instanceof Element && c.contains(l);
})
)) return;
const o = n.reduce((l, s) => {
const c = s instanceof Element ? e.findIndex((m) => m.element === s) : -1;
return l === -1 && c !== -1 ? c : l;
}, -1);
o === -1 ? i(0) : o + 1 <= e.length - 1 && i(o + 1);
}, d = (n) => {
const t = e.findIndex((o) => o.element === n);
t >= 0 && e.splice(t, 1);
}, f = (n, t) => {
e.findIndex((l) => l.element === n) >= 0 || e.push({ element: n, callback: t });
}, i = (n) => {
const t = e.length;
for (let o = n; o < t; o++)
e?.[o]?.callback?.();
e.splice(n);
};
return { add: f, remove: d, closeAll: () => {
e.forEach((n) => n?.callback?.()), e = [];
}, closePopoversOutsideOfClick: r };
})();
export {
u as popoverUtil
};