UNPKG

@agnos-ui/core

Version:

Framework-agnostic headless component library.

41 lines (40 loc) 1.48 kB
import { computed } from "@amadeus-it-group/tansu"; import { noop } from "../utils/func.js"; import { g as createBrowserStoreArrayDirective, k as mergeDirectives, d as directiveSubscribe } from "../dom-gfxqXJpK.js"; const internalSetSiblingsInert = (element) => { const inertValues = /* @__PURE__ */ new Map(); const recursiveHelper = (element2) => { const parent = element2.parentElement; if (parent && element2 !== document.body) { Array.from(parent.children).forEach((sibling) => { if (sibling !== element2 && sibling.nodeName !== "SCRIPT") { inertValues.set(sibling, sibling.hasAttribute("inert")); sibling.toggleAttribute("inert", true); } }); recursiveHelper(parent); } }; recursiveHelper(element); return () => inertValues.forEach((value, element2) => { element2.toggleAttribute("inert", value); }); }; let internalRevert = noop; const setSiblingsInert = (element) => { internalRevert(); internalRevert = element ? internalSetSiblingsInert(element) : noop; }; const { directive: storeArrayDirective, elements$ } = createBrowserStoreArrayDirective(); const lastElement$ = computed( () => { const elements = elements$(); return elements[elements.length - 1]; }, { equal: Object.is } ); const inertAction$ = computed(() => setSiblingsInert(lastElement$())); const siblingsInert = mergeDirectives(storeArrayDirective, directiveSubscribe(inertAction$)); export { siblingsInert };