@purpurds/tabs 4.4.0 → 4.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/tabs.es.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsx as N, jsxs as Q } from "react/jsx-runtime";
2
2
  import * as be from "react";
3
- import A, { createContext as te, useMemo as Z, createElement as h, useContext as $e, useCallback as L, forwardRef as T, Children as E, isValidElement as K, cloneElement as ce, Fragment as Me, useLayoutEffect as Oe, useEffect as R, useRef as P, useState as O, useReducer as Fe } from "react";
3
+ import A, { createContext as te, useMemo as Z, createElement as g, useContext as $e, useCallback as L, forwardRef as T, Children as E, isValidElement as K, cloneElement as ce, Fragment as Me, useLayoutEffect as Oe, useEffect as R, useRef as P, useState as O, useReducer as Fe } from "react";
4
4
  import { flushSync as De } from "react-dom";
5
5
  function qe(e) {
6
6
  return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
@@ -116,12 +116,12 @@ function se(e, t = []) {
116
116
  c
117
117
  ];
118
118
  function i(d) {
119
- const { scope: b, children: v, ...l } = d, $ = (b == null ? void 0 : b[e][u]) || a, g = Z(
119
+ const { scope: b, children: v, ...l } = d, $ = (b == null ? void 0 : b[e][u]) || a, h = Z(
120
120
  () => l,
121
121
  Object.values(l)
122
122
  );
123
- return /* @__PURE__ */ h($.Provider, {
124
- value: g
123
+ return /* @__PURE__ */ g($.Provider, {
124
+ value: h
125
125
  }, v);
126
126
  }
127
127
  function f(d, b) {
@@ -206,11 +206,11 @@ const X = /* @__PURE__ */ T((e, t) => {
206
206
  const { children: n, ...o } = e, s = E.toArray(n), r = s.find(Je);
207
207
  if (r) {
208
208
  const c = r.props.children, a = s.map((u) => u === r ? E.count(c) > 1 ? E.only(null) : /* @__PURE__ */ K(c) ? c.props.children : null : u);
209
- return /* @__PURE__ */ h(ne, y({}, o, {
209
+ return /* @__PURE__ */ g(ne, y({}, o, {
210
210
  ref: t
211
211
  }), /* @__PURE__ */ K(c) ? /* @__PURE__ */ ce(c, void 0, a) : null);
212
212
  }
213
- return /* @__PURE__ */ h(ne, y({}, o, {
213
+ return /* @__PURE__ */ g(ne, y({}, o, {
214
214
  ref: t
215
215
  }), n);
216
216
  });
@@ -223,7 +223,7 @@ const ne = /* @__PURE__ */ T((e, t) => {
223
223
  }) : E.count(n) > 1 ? E.only(null) : null;
224
224
  });
225
225
  ne.displayName = "SlotClone";
226
- const Xe = ({ children: e }) => /* @__PURE__ */ h(Me, null, e);
226
+ const Xe = ({ children: e }) => /* @__PURE__ */ g(Me, null, e);
227
227
  function Je(e) {
228
228
  return /* @__PURE__ */ K(e) && e.type === Xe;
229
229
  }
@@ -255,34 +255,34 @@ function et(e) {
255
255
  },
256
256
  itemMap: /* @__PURE__ */ new Map()
257
257
  }), c = (v) => {
258
- const { scope: l, children: $ } = v, g = A.useRef(null), m = A.useRef(/* @__PURE__ */ new Map()).current;
258
+ const { scope: l, children: $ } = v, h = A.useRef(null), m = A.useRef(/* @__PURE__ */ new Map()).current;
259
259
  return /* @__PURE__ */ A.createElement(s, {
260
260
  scope: l,
261
261
  itemMap: m,
262
- collectionRef: g
262
+ collectionRef: h
263
263
  }, $);
264
264
  }, a = e + "CollectionSlot", u = /* @__PURE__ */ A.forwardRef((v, l) => {
265
- const { scope: $, children: g } = v, m = r(a, $), _ = H(l, m.collectionRef);
265
+ const { scope: $, children: h } = v, m = r(a, $), _ = H(l, m.collectionRef);
266
266
  return /* @__PURE__ */ A.createElement(X, {
267
267
  ref: _
268
- }, g);
268
+ }, h);
269
269
  }), i = e + "CollectionItemSlot", f = "data-radix-collection-item", d = /* @__PURE__ */ A.forwardRef((v, l) => {
270
- const { scope: $, children: g, ...m } = v, _ = A.useRef(null), U = H(l, _), S = r(i, $);
270
+ const { scope: $, children: h, ...m } = v, _ = A.useRef(null), U = H(l, _), S = r(i, $);
271
271
  return A.useEffect(() => (S.itemMap.set(_, {
272
272
  ref: _,
273
273
  ...m
274
274
  }), () => void S.itemMap.delete(_))), /* @__PURE__ */ A.createElement(X, {
275
275
  [f]: "",
276
276
  ref: U
277
- }, g);
277
+ }, h);
278
278
  });
279
279
  function b(v) {
280
280
  const l = r(e + "CollectionConsumer", v);
281
281
  return A.useCallback(() => {
282
- const g = l.collectionRef.current;
283
- if (!g)
282
+ const h = l.collectionRef.current;
283
+ if (!h)
284
284
  return [];
285
- const m = Array.from(g.querySelectorAll(`[${f}]`));
285
+ const m = Array.from(h.querySelectorAll(`[${f}]`));
286
286
  return Array.from(l.itemMap.values()).sort(
287
287
  (S, j) => m.indexOf(S.ref.current) - m.indexOf(j.ref.current)
288
288
  );
@@ -337,7 +337,7 @@ const rt = [
337
337
  const { asChild: r, ...c } = o, a = r ? X : t;
338
338
  return R(() => {
339
339
  window[Symbol.for("radix-ui")] = !0;
340
- }, []), /* @__PURE__ */ h(a, y({}, c, {
340
+ }, []), /* @__PURE__ */ g(a, y({}, c, {
341
341
  ref: s
342
342
  }));
343
343
  });
@@ -358,7 +358,7 @@ function ae(e) {
358
358
  []
359
359
  );
360
360
  }
361
- function he({ prop: e, defaultProp: t, onChange: n = () => {
361
+ function ge({ prop: e, defaultProp: t, onChange: n = () => {
362
362
  } }) {
363
363
  const [o, s] = ot({
364
364
  defaultProp: t,
@@ -391,41 +391,41 @@ function ot({ defaultProp: e, onChange: t }) {
391
391
  ]), n;
392
392
  }
393
393
  const ct = /* @__PURE__ */ te(void 0);
394
- function ge(e) {
394
+ function he(e) {
395
395
  const t = $e(ct);
396
396
  return e || t || "ltr";
397
397
  }
398
398
  const ee = "rovingFocusGroup.onEntryFocus", st = {
399
399
  bubbles: !1,
400
400
  cancelable: !0
401
- }, ie = "RovingFocusGroup", [oe, xe, at] = et(ie), [it, Ce] = se(ie, [
401
+ }, ie = "RovingFocusGroup", [oe, xe, at] = et(ie), [it, Ie] = se(ie, [
402
402
  at
403
- ]), [ut, lt] = it(ie), dt = /* @__PURE__ */ T((e, t) => /* @__PURE__ */ h(oe.Provider, {
403
+ ]), [ut, lt] = it(ie), dt = /* @__PURE__ */ T((e, t) => /* @__PURE__ */ g(oe.Provider, {
404
404
  scope: e.__scopeRovingFocusGroup
405
- }, /* @__PURE__ */ h(oe.Slot, {
405
+ }, /* @__PURE__ */ g(oe.Slot, {
406
406
  scope: e.__scopeRovingFocusGroup
407
- }, /* @__PURE__ */ h(ft, y({}, e, {
407
+ }, /* @__PURE__ */ g(ft, y({}, e, {
408
408
  ref: t
409
409
  }))))), ft = /* @__PURE__ */ T((e, t) => {
410
- const { __scopeRovingFocusGroup: n, orientation: o, loop: s = !1, dir: r, currentTabStopId: c, defaultCurrentTabStopId: a, onCurrentTabStopIdChange: u, onEntryFocus: i, ...f } = e, d = P(null), b = H(t, d), v = ge(r), [l = null, $] = he({
410
+ const { __scopeRovingFocusGroup: n, orientation: o, loop: s = !1, dir: r, currentTabStopId: c, defaultCurrentTabStopId: a, onCurrentTabStopIdChange: u, onEntryFocus: i, ...f } = e, d = P(null), b = H(t, d), v = he(r), [l = null, $] = ge({
411
411
  prop: c,
412
412
  defaultProp: a,
413
413
  onChange: u
414
- }), [g, m] = O(!1), _ = ae(i), U = xe(n), S = P(!1), [j, G] = O(0);
414
+ }), [h, m] = O(!1), _ = ae(i), U = xe(n), S = P(!1), [j, G] = O(0);
415
415
  return R(() => {
416
- const C = d.current;
417
- if (C)
418
- return C.addEventListener(ee, _), () => C.removeEventListener(ee, _);
416
+ const I = d.current;
417
+ if (I)
418
+ return I.addEventListener(ee, _), () => I.removeEventListener(ee, _);
419
419
  }, [
420
420
  _
421
- ]), /* @__PURE__ */ h(ut, {
421
+ ]), /* @__PURE__ */ g(ut, {
422
422
  scope: n,
423
423
  orientation: o,
424
424
  dir: v,
425
425
  loop: s,
426
426
  currentTabStopId: l,
427
427
  onItemFocus: L(
428
- (C) => $(C),
428
+ (I) => $(I),
429
429
  [
430
430
  $
431
431
  ]
@@ -436,18 +436,18 @@ const ee = "rovingFocusGroup.onEntryFocus", st = {
436
436
  ),
437
437
  onFocusableItemAdd: L(
438
438
  () => G(
439
- (C) => C + 1
439
+ (I) => I + 1
440
440
  ),
441
441
  []
442
442
  ),
443
443
  onFocusableItemRemove: L(
444
444
  () => G(
445
- (C) => C - 1
445
+ (I) => I - 1
446
446
  ),
447
447
  []
448
448
  )
449
- }, /* @__PURE__ */ h(B.div, y({
450
- tabIndex: g || j === 0 ? -1 : 0,
449
+ }, /* @__PURE__ */ g(B.div, y({
450
+ tabIndex: h || j === 0 ? -1 : 0,
451
451
  "data-orientation": o
452
452
  }, f, {
453
453
  ref: b,
@@ -458,25 +458,25 @@ const ee = "rovingFocusGroup.onEntryFocus", st = {
458
458
  onMouseDown: M(e.onMouseDown, () => {
459
459
  S.current = !0;
460
460
  }),
461
- onFocus: M(e.onFocus, (C) => {
461
+ onFocus: M(e.onFocus, (I) => {
462
462
  const k = !S.current;
463
- if (C.target === C.currentTarget && k && !g) {
463
+ if (I.target === I.currentTarget && k && !h) {
464
464
  const V = new CustomEvent(ee, st);
465
- if (C.currentTarget.dispatchEvent(V), !V.defaultPrevented) {
465
+ if (I.currentTarget.dispatchEvent(V), !V.defaultPrevented) {
466
466
  const z = U().filter(
467
467
  (x) => x.focusable
468
468
  ), J = z.find(
469
469
  (x) => x.active
470
470
  ), W = z.find(
471
471
  (x) => x.id === l
472
- ), I = [
472
+ ), C = [
473
473
  J,
474
474
  W,
475
475
  ...z
476
476
  ].filter(Boolean).map(
477
477
  (x) => x.ref.current
478
478
  );
479
- Ie(I);
479
+ Ce(C);
480
480
  }
481
481
  }
482
482
  S.current = !1;
@@ -495,12 +495,12 @@ const ee = "rovingFocusGroup.onEntryFocus", st = {
495
495
  o,
496
496
  b,
497
497
  v
498
- ]), /* @__PURE__ */ h(oe.ItemSlot, {
498
+ ]), /* @__PURE__ */ g(oe.ItemSlot, {
499
499
  scope: n,
500
500
  id: u,
501
501
  focusable: o,
502
502
  active: s
503
- }, /* @__PURE__ */ h(B.span, y({
503
+ }, /* @__PURE__ */ g(B.span, y({
504
504
  tabIndex: f ? 0 : -1,
505
505
  "data-orientation": i.orientation
506
506
  }, c, {
@@ -535,7 +535,7 @@ const ee = "rovingFocusGroup.onEntryFocus", st = {
535
535
  m = i.loop ? _t(m, _ + 1) : m.slice(_ + 1);
536
536
  }
537
537
  setTimeout(
538
- () => Ie(m)
538
+ () => Ce(m)
539
539
  );
540
540
  }
541
541
  })
@@ -564,7 +564,7 @@ function mt(e, t, n) {
564
564
  ].includes(o)))
565
565
  return $t[o];
566
566
  }
567
- function Ie(e) {
567
+ function Ce(e) {
568
568
  const t = document.activeElement;
569
569
  for (const n of e)
570
570
  if (n === t || (n.focus(), document.activeElement !== t))
@@ -575,7 +575,7 @@ function _t(e, t) {
575
575
  (n, o) => e[(t + o) % e.length]
576
576
  );
577
577
  }
578
- const ht = dt, gt = bt;
578
+ const gt = dt, ht = bt;
579
579
  function xt(e, t) {
580
580
  return Fe((n, o) => {
581
581
  const s = t[n][o];
@@ -583,7 +583,7 @@ function xt(e, t) {
583
583
  }, e);
584
584
  }
585
585
  const ye = (e) => {
586
- const { present: t, children: n } = e, o = Ct(t), s = typeof n == "function" ? n({
586
+ const { present: t, children: n } = e, o = It(t), s = typeof n == "function" ? n({
587
587
  present: o.isPresent
588
588
  }) : E.only(n), r = H(o.ref, s.ref);
589
589
  return typeof n == "function" || o.isPresent ? /* @__PURE__ */ ce(s, {
@@ -591,7 +591,7 @@ const ye = (e) => {
591
591
  }) : null;
592
592
  };
593
593
  ye.displayName = "Presence";
594
- function Ct(e) {
594
+ function It(e) {
595
595
  const [t, n] = O(), o = P({}), s = P(e), r = P("none"), c = e ? "mounted" : "unmounted", [a, u] = xt(c, {
596
596
  mounted: {
597
597
  UNMOUNT: "unmounted",
@@ -650,15 +650,15 @@ function Ct(e) {
650
650
  function Y(e) {
651
651
  return (e == null ? void 0 : e.animationName) || "none";
652
652
  }
653
- const Se = "Tabs", [It, Qt] = se(Se, [
654
- Ce
655
- ]), we = Ce(), [yt, ue] = It(Se), St = /* @__PURE__ */ T((e, t) => {
656
- const { __scopeTabs: n, value: o, onValueChange: s, defaultValue: r, orientation: c = "horizontal", dir: a, activationMode: u = "automatic", ...i } = e, f = ge(a), [d, b] = he({
653
+ const Se = "Tabs", [Ct, Qt] = se(Se, [
654
+ Ie
655
+ ]), we = Ie(), [yt, ue] = Ct(Se), St = /* @__PURE__ */ T((e, t) => {
656
+ const { __scopeTabs: n, value: o, onValueChange: s, defaultValue: r, orientation: c = "horizontal", dir: a, activationMode: u = "automatic", ...i } = e, f = he(a), [d, b] = ge({
657
657
  prop: o,
658
658
  onChange: s,
659
659
  defaultProp: r
660
660
  });
661
- return /* @__PURE__ */ h(yt, {
661
+ return /* @__PURE__ */ g(yt, {
662
662
  scope: n,
663
663
  baseId: _e(),
664
664
  value: d,
@@ -666,7 +666,7 @@ const Se = "Tabs", [It, Qt] = se(Se, [
666
666
  orientation: c,
667
667
  dir: f,
668
668
  activationMode: u
669
- }, /* @__PURE__ */ h(B.div, y({
669
+ }, /* @__PURE__ */ g(B.div, y({
670
670
  dir: f,
671
671
  "data-orientation": c
672
672
  }, i, {
@@ -674,13 +674,13 @@ const Se = "Tabs", [It, Qt] = se(Se, [
674
674
  })));
675
675
  }), wt = "TabsList", Tt = /* @__PURE__ */ T((e, t) => {
676
676
  const { __scopeTabs: n, loop: o = !0, ...s } = e, r = ue(wt, n), c = we(n);
677
- return /* @__PURE__ */ h(ht, y({
677
+ return /* @__PURE__ */ g(gt, y({
678
678
  asChild: !0
679
679
  }, c, {
680
680
  orientation: r.orientation,
681
681
  dir: r.dir,
682
682
  loop: o
683
- }), /* @__PURE__ */ h(B.div, y({
683
+ }), /* @__PURE__ */ g(B.div, y({
684
684
  role: "tablist",
685
685
  "aria-orientation": r.orientation
686
686
  }, s, {
@@ -688,12 +688,12 @@ const Se = "Tabs", [It, Qt] = se(Se, [
688
688
  })));
689
689
  }), Nt = "TabsTrigger", At = /* @__PURE__ */ T((e, t) => {
690
690
  const { __scopeTabs: n, value: o, disabled: s = !1, ...r } = e, c = ue(Nt, n), a = we(n), u = Te(c.baseId, o), i = Ne(c.baseId, o), f = o === c.value;
691
- return /* @__PURE__ */ h(gt, y({
691
+ return /* @__PURE__ */ g(ht, y({
692
692
  asChild: !0
693
693
  }, a, {
694
694
  focusable: !s,
695
695
  active: f
696
- }), /* @__PURE__ */ h(B.button, y({
696
+ }), /* @__PURE__ */ g(B.button, y({
697
697
  type: "button",
698
698
  role: "tab",
699
699
  "aria-selected": f,
@@ -725,12 +725,12 @@ const Se = "Tabs", [It, Qt] = se(Se, [
725
725
  () => d.current = !1
726
726
  );
727
727
  return () => cancelAnimationFrame(b);
728
- }, []), /* @__PURE__ */ h(
728
+ }, []), /* @__PURE__ */ g(
729
729
  ye,
730
730
  {
731
731
  present: s || f
732
732
  },
733
- ({ present: b }) => /* @__PURE__ */ h(B.div, y({
733
+ ({ present: b }) => /* @__PURE__ */ g(B.div, y({
734
734
  "data-state": f ? "active" : "inactive",
735
735
  "data-orientation": a.orientation,
736
736
  role: "tabpanel",
@@ -809,11 +809,11 @@ const le = /* @__PURE__ */ Dt(qt), Lt = {
809
809
  }
810
810
  )
811
811
  ), jt = (e) => !!e && K(e) && !!e.props.name && !!e.props.tabId, Gt = {
812
- "purpur-tab-header": "_purpur-tab-header_1hk4f_1",
813
- "purpur-tab-header--contained": "_purpur-tab-header--contained_1hk4f_32",
814
- "purpur-tab-header--contained-negative": "_purpur-tab-header--contained-negative_1hk4f_32",
815
- "purpur-tab-header--line": "_purpur-tab-header--line_1hk4f_35",
816
- "purpur-tab-header--line-negative": "_purpur-tab-header--line-negative_1hk4f_47"
812
+ "purpur-tab-header": "_purpur-tab-header_ls5xt_1",
813
+ "purpur-tab-header--contained": "_purpur-tab-header--contained_ls5xt_32",
814
+ "purpur-tab-header--contained-negative": "_purpur-tab-header--contained-negative_ls5xt_32",
815
+ "purpur-tab-header--line": "_purpur-tab-header--line_ls5xt_35",
816
+ "purpur-tab-header--line-negative": "_purpur-tab-header--line-negative_ls5xt_47"
817
817
  }, kt = le.bind(Gt), pe = "purpur-tab-header", zt = T(
818
818
  ({ index: e, tabId: t, variant: n, onFocus: o, "data-testid": s, children: r }, c) => /* @__PURE__ */ N(
819
819
  Ot,
@@ -860,25 +860,25 @@ const le = /* @__PURE__ */ Dt(qt), Lt = {
860
860
  "data-testid": c,
861
861
  ...a
862
862
  }) => {
863
- const [u, i] = O({}), [f, d] = O(0), [b, v] = O(0), l = E.toArray(e).filter(jt), $ = P(), g = P(new Array(l.length)), m = 200, _ = t === "line" || t === "line-negative", U = q([
863
+ const [u, i] = O({}), [f, d] = O(0), [b, v] = O(0), l = E.toArray(e).filter(jt), $ = P(), h = P(new Array(l.length)), m = 200, _ = t === "line" || t === "line-negative", U = q([
864
864
  w,
865
865
  `${w}--${t}`,
866
866
  { [`${w}--fullWidth`]: n },
867
867
  s
868
- ]), S = E.map(l, ({ props: { tabId: p } }) => p), j = () => S.findIndex((p) => p === r) || 0, [G, C] = O(j);
868
+ ]), S = E.map(l, ({ props: { tabId: p } }) => p), j = () => S.findIndex((p) => p === r) || 0, [G, I] = O(j);
869
869
  if (new Set(S).size !== S.length)
870
870
  throw new Error("tabId must be unique");
871
- const k = (p, I) => I || c ? `${I || c}-${p}` : void 0, V = () => {
871
+ const k = (p, C) => C || c ? `${C || c}-${p}` : void 0, V = () => {
872
872
  if (!_)
873
873
  return;
874
- const p = g.current[G];
874
+ const p = h.current[G];
875
875
  d((p == null ? void 0 : p.offsetLeft) || 0), v((p == null ? void 0 : p.getBoundingClientRect().width) || 0);
876
876
  }, z = (p) => {
877
- _ && C(l.findIndex((I) => I.props.tabId === p)), o == null || o(Wt(p));
877
+ _ && I(l.findIndex((C) => C.props.tabId === p)), o == null || o(Wt(p));
878
878
  }, J = (p) => {
879
879
  if ($ != null && $.current) {
880
- const { scrollLeft: I } = $.current, x = p === "left" ? -m : m;
881
- $.current.scroll({ left: I + x, behavior: "smooth" });
880
+ const { scrollLeft: C } = $.current, x = p === "left" ? -m : m;
881
+ $.current.scroll({ left: C + x, behavior: "smooth" });
882
882
  }
883
883
  }, W = ({ side: p }) => /* @__PURE__ */ N(
884
884
  "button",
@@ -914,17 +914,17 @@ const le = /* @__PURE__ */ Dt(qt), Lt = {
914
914
  }
915
915
  }));
916
916
  });
917
- }, I = new IntersectionObserver(p, {
917
+ }, C = new IntersectionObserver(p, {
918
918
  threshold: [0.99],
919
919
  root: $.current
920
920
  });
921
- return g.current.forEach((x) => I.observe(x)), () => {
922
- g.current.forEach((x) => I.unobserve(x));
921
+ return h.current.forEach((x) => C.observe(x)), () => {
922
+ h.current.forEach((x) => C.unobserve(x));
923
923
  };
924
924
  }, [l.length]), /* @__PURE__ */ N(
925
925
  Pt,
926
926
  {
927
- defaultValue: r,
927
+ defaultValue: r ?? l[0].props.tabId,
928
928
  onValueChange: z,
929
929
  "data-testid": c,
930
930
  className: U,
@@ -939,16 +939,16 @@ const le = /* @__PURE__ */ Dt(qt), Lt = {
939
939
  },
940
940
  className: q(`${w}__list`),
941
941
  children: [
942
- E.map(l, (p, I) => {
942
+ E.map(l, (p, C) => {
943
943
  const { name: x, tabId: de, "data-testid": F } = p.props;
944
944
  return /* @__PURE__ */ N(
945
945
  zt,
946
946
  {
947
947
  "data-testid": k("header", F),
948
- index: I,
948
+ index: C,
949
949
  tabId: de,
950
950
  ref: (D) => {
951
- D && (g.current[I] = D);
951
+ D && (h.current[C] = D);
952
952
  },
953
953
  onFocus: (D) => {
954
954
  Yt(D.target, $.current);