tab.mjs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import { B as q, N as p, W as Q, G as f, Q as E, h as v, _ as l, o as d, Z as T, a as b, s as y, t as z, m as C, e as W, j as F, a8 as H, E as J, r as K, v as O } from "./base-component-BMXjNJAi.mjs";
  2. import { c as _ } from "./collapsingClass-BxKtDBMH.mjs";
  3. import { a as c } from "./activeClass-iqaD75Su.mjs";
  4. import { f as h } from "./fadeClass-CLIYI_zn.mjs";
  5. import { s as w } from "./showClass-C8hdJfjQ.mjs";
  6. import { d as B } from "./dropdownClasses-CdCdZ-PX.mjs";
  7. import { d as R } from "./dataBsToggle-B84TS15h.mjs";
  8. import { g as P } from "./getTargetElement-px782XHx.mjs";
  9. const m = "tab", Z = "Tab", j = `[${R}="${m}"]`, A = (s) => z(s, Z), U = (s) => new X(s), x = C(
  10. `show.bs.${m}`
  11. ), I = C(
  12. `shown.bs.${m}`
  13. ), $ = C(
  14. `hide.bs.${m}`
  15. ), L = C(
  16. `hidden.bs.${m}`
  17. ), u = /* @__PURE__ */ new Map(), S = (s) => {
  18. const { tabContent: e, nav: t } = s;
  19. e && l(e, _) && (e.style.height = "", b(e, _)), t && v.clear(t);
  20. }, k = (s) => {
  21. const { element: e, tabContent: t, content: n, nav: i } = s, { tab: o } = d(i) && u.get(i) || { tab: null };
  22. if (t && n && l(n, h)) {
  23. const { currentHeight: a, nextHeight: r } = u.get(e) || { currentHeight: 0, nextHeight: 0 };
  24. a !== r ? setTimeout(() => {
  25. t.style.height = `${r}px`, W(t), y(t, () => S(s));
  26. }, 50) : S(s);
  27. } else i && v.clear(i);
  28. I.relatedTarget = o, T(e, I);
  29. }, G = (s) => {
  30. const { element: e, content: t, tabContent: n, nav: i } = s, { tab: o, content: a } = i && u.get(i) || { tab: null, content: null };
  31. let r = 0;
  32. if (n && t && l(t, h) && ([a, t].forEach((g) => {
  33. g && f(g, "overflow-hidden");
  34. }), r = a ? a.scrollHeight : 0), x.relatedTarget = o, L.relatedTarget = e, T(e, x), !x.defaultPrevented) {
  35. if (t && f(t, c), a && b(a, c), n && t && l(t, h)) {
  36. const g = t.scrollHeight;
  37. u.set(e, {
  38. currentHeight: r,
  39. nextHeight: g,
  40. tab: null,
  41. content: null
  42. }), f(n, _), n.style.height = `${r}px`, W(n), [a, t].forEach((D) => {
  43. D && b(D, "overflow-hidden");
  44. });
  45. }
  46. t && t && l(t, h) ? setTimeout(() => {
  47. f(t, w), y(t, () => {
  48. k(s);
  49. });
  50. }, 1) : (t && f(t, w), k(s)), o && T(o, L);
  51. }
  52. }, M = (s) => {
  53. const { nav: e } = s;
  54. if (!d(e))
  55. return { tab: null, content: null };
  56. const t = F(
  57. c,
  58. e
  59. );
  60. let n = null;
  61. t.length === 1 && !B.some(
  62. (o) => l(t[0].parentElement, o)
  63. ) ? [n] = t : t.length > 1 && (n = t[t.length - 1]);
  64. const i = d(n) ? P(n) : null;
  65. return { tab: n, content: i };
  66. }, N = (s) => {
  67. if (!d(s)) return null;
  68. const e = p(s, `.${B.join(",.")}`);
  69. return e ? Q(`.${B[0]}-toggle`, e) : null;
  70. }, V = (s) => {
  71. const e = p(s.target, j), t = e && A(e);
  72. t && (s.preventDefault(), t.show());
  73. };
  74. class X extends q {
  75. static selector = j;
  76. static init = U;
  77. static getInstance = A;
  78. constructor(e) {
  79. super(e);
  80. const { element: t } = this, n = P(t);
  81. if (!n) return;
  82. const i = p(t, ".nav"), o = p(
  83. n,
  84. ".tab-content"
  85. );
  86. this.nav = i, this.content = n, this.tabContent = o, this.dropdown = N(t);
  87. const { tab: a } = M(this);
  88. if (i && !a) {
  89. const r = Q(j, i), g = r && P(r);
  90. g && (f(r, c), f(g, w), f(g, c), E(t, H, "true"));
  91. }
  92. this._toggleEventListeners(!0);
  93. }
  94. get name() {
  95. return Z;
  96. }
  97. show() {
  98. const { element: e, content: t, nav: n, dropdown: i } = this;
  99. if (n && v.get(n) || l(e, c)) return;
  100. const { tab: o, content: a } = M(this);
  101. if (n && o && u.set(n, { tab: o, content: a, currentHeight: 0, nextHeight: 0 }), $.relatedTarget = e, !d(o) || (T(o, $), $.defaultPrevented)) return;
  102. f(e, c), E(e, H, "true");
  103. const r = d(o) && N(o);
  104. if (r && l(r, c) && b(r, c), n) {
  105. const g = () => {
  106. o && (b(o, c), E(o, H, "false")), i && !l(i, c) && f(i, c);
  107. };
  108. a && (l(a, h) || t && l(t, h)) ? v.set(n, g, 1) : g();
  109. }
  110. a && (b(a, w), l(a, h) ? y(a, () => G(this)) : G(this));
  111. }
  112. _toggleEventListeners = (e) => {
  113. (e ? J : K)(this.element, O, V);
  114. };
  115. dispose() {
  116. this._toggleEventListeners(), super.dispose();
  117. }
  118. }
  119. export {
  120. X as default
  121. };
  122. //# sourceMappingURL=tab.mjs.map