UNPKG

bootstrap-vue-next

Version:

BootstrapVueNext is an early and lovely component library for Vue 3 & Nuxt 3 based on Bootstrap 5 and Typescript.

77 lines (76 loc) 2.8 kB
import { n as RX_SPACE_SPLIT, o as RX_HASH_ID, p as RX_HASH } from "../../../constants-COk0ugyL.mjs"; import { f as findProvides } from "../../../utils-DPq73bs8.mjs"; import { g as globalShowHideStorageInjectionKey } from "../../../keys-BZewGSMQ.mjs"; const getTargets = (binding, el) => { const { modifiers, arg, value } = binding; const targets = Object.keys(modifiers || {}); const localValue = typeof value === "string" ? value.split(RX_SPACE_SPLIT) : value; if (el.tagName.toLowerCase() === "a") { const href = el.getAttribute("href") || ""; if (RX_HASH_ID.test(href)) { targets.push(href.replace(RX_HASH, "")); } } Array.prototype.concat.apply([], [arg, localValue]).forEach((t) => typeof t === "string" && targets.push(t)); return targets.filter((t, index, arr) => t && arr.indexOf(t) === index); }; const toggle = (targetIds, el, binding, vnode) => { var _a; const provides = findProvides(binding, vnode); const showHide = (_a = provides[globalShowHideStorageInjectionKey]) == null ? void 0 : _a.map; targetIds.forEach((targetId) => { if (showHide == null ? void 0 : showHide[targetId]) { showHide[targetId].toggle(); return; } const target = document.getElementById(targetId); if (target !== null) { target.dispatchEvent(new Event("bv-toggle")); } }); setTimeout(() => checkVisibility(targetIds, el), 50); }; const checkVisibility = (targetIds, el) => { let visible = false; targetIds.forEach((targetId) => { const target = document.getElementById(targetId); if (target == null ? void 0 : target.classList.contains("show")) { visible = true; } if (target == null ? void 0 : target.classList.contains("closing")) { visible = false; } }); el.setAttribute("aria-expanded", visible ? "true" : "false"); el.classList.remove(visible ? "collapsed" : "not-collapsed"); el.classList.add(visible ? "not-collapsed" : "collapsed"); }; const handleUpdate = (el, binding, vnode) => { const targets = getTargets(binding, el); if (targets.length === 0) return; if (el.__toggle) { setTimeout(() => { el.removeEventListener("click", el.__toggle); el.__toggle = () => toggle(targets, el, binding, vnode); el.addEventListener("click", el.__toggle); }, 0); } else { el.__toggle = () => toggle(targets, el, binding, vnode); el.addEventListener("click", el.__toggle); } el.setAttribute("aria-controls", targets.join(" ")); checkVisibility(targets, el); }; const vBToggle = { mounted: handleUpdate, updated: handleUpdate, unmounted(el) { el.removeEventListener("click", el.__toggle); el.removeAttribute("aria-controls"); el.removeAttribute("aria-expanded"); } }; export { vBToggle }; //# sourceMappingURL=index.mjs.map